From 02ff9967fb10e94a3491def9377629ac39e98347 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Mon, 6 May 2024 12:52:56 +0000 Subject: [PATCH 001/240] fix log --- source/util/src/tsched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/util/src/tsched.c b/source/util/src/tsched.c index 603547e30b..6a1efb5d24 100644 --- a/source/util/src/tsched.c +++ b/source/util/src/tsched.c @@ -28,7 +28,7 @@ static void taosDumpSchedulerStatus(void *qhandle, void *tmrId); void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *label, SSchedQueue *pSched) { bool schedMalloced = false; - + if (NULL == pSched) { pSched = (SSchedQueue *)taosMemoryCalloc(sizeof(SSchedQueue), 1); if (pSched == NULL) { @@ -100,7 +100,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab int32_t code = taosThreadCreate(pSched->qthread + i, &attr, taosProcessSchedQueue, (void *)pSched); taosThreadAttrDestroy(&attr); if (code != 0) { - uError("%s: failed to create rpc thread(%s)", label, strerror(errno)); + uError("%s: failed to create thread(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); if (schedMalloced) { taosMemoryFree(pSched); From 8c11a7e998ef94b2715a7092214d5c6efe981b83 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Tue, 7 May 2024 03:10:35 +0000 Subject: [PATCH 002/240] refactor transport --- source/libs/transport/src/transCli.c | 156 +++++++++++++-------------- 1 file changed, 77 insertions(+), 79 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index dfd7630f35..86d6ef58ff 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -212,8 +212,10 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd); static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd); static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL, cliHandleUpdate}; -/// static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, -/// NULL,cliHandleUpdate}; + +static void cliDealReq(queue* h, SCliThrd* pThrd); +static void cliBatchDealReq(queue* h, SCliThrd* pThrd); +static void (*cliDealFunc[])(queue* h, SCliThrd* pThrd) = {cliDealReq, cliBatchDealReq}; static FORCE_INLINE void destroyCmsg(void* cmsg); @@ -1695,7 +1697,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { tGTrace("%s conn %p ready", pTransInst->label, conn); } -static void cliNoBatchDealReq(queue* wq, SCliThrd* pThrd) { +static void cliDealReq(queue* wq, SCliThrd* pThrd) { int count = 0; while (!QUEUE_IS_EMPTY(wq)) { @@ -1709,7 +1711,6 @@ static void cliNoBatchDealReq(queue* wq, SCliThrd* pThrd) { continue; } (*cliAsyncHandle[pMsg->type])(pMsg, pThrd); - count++; } if (count >= 2) { @@ -1729,7 +1730,77 @@ SCliBatch* cliGetHeadFromList(SCliBatchList* pList) { SCliBatch* batch = QUEUE_DATA(hr, SCliBatch, listq); return batch; } +static void cliBuildBatch(SCliMsg* pMsg, queue* h, SCliThrd* pThrd) { + STrans* pInst = pThrd->pTransInst; + STransConnCtx* pCtx = pMsg->ctx; + char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet); + uint32_t port = EPSET_GET_INUSE_PORT(&pCtx->epSet); + char key[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(key, ip, port); + size_t klen = strlen(key); + SCliBatchList** ppBatchList = taosHashGet(pThrd->batchCache, key, klen); + if (ppBatchList == NULL || *ppBatchList == NULL) { + SCliBatchList* pBatchList = taosMemoryCalloc(1, sizeof(SCliBatchList)); + QUEUE_INIT(&pBatchList->wq); + pBatchList->connMax = pInst->connLimitNum; + pBatchList->connCnt = 0; + pBatchList->batchLenLimit = pInst->batchSize; + pBatchList->len += 1; + + pBatchList->ip = taosStrdup(ip); + pBatchList->dst = taosStrdup(key); + pBatchList->port = port; + + SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); + QUEUE_INIT(&pBatch->wq); + QUEUE_INIT(&pBatch->listq); + + QUEUE_PUSH(&pBatch->wq, h); + pBatch->wLen += 1; + pBatch->batchSize += pMsg->msg.contLen; + pBatch->pList = pBatchList; + + QUEUE_PUSH(&pBatchList->wq, &pBatch->listq); + + taosHashPut(pThrd->batchCache, key, klen, &pBatchList, sizeof(void*)); + } else { + if (QUEUE_IS_EMPTY(&(*ppBatchList)->wq)) { + SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); + QUEUE_INIT(&pBatch->wq); + QUEUE_INIT(&pBatch->listq); + + QUEUE_PUSH(&pBatch->wq, h); + pBatch->wLen += 1; + pBatch->batchSize = pMsg->msg.contLen; + pBatch->pList = *ppBatchList; + + QUEUE_PUSH(&((*ppBatchList)->wq), &pBatch->listq); + (*ppBatchList)->len += 1; + } + + queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); + SCliBatch* pBatch = QUEUE_DATA(hdr, SCliBatch, listq); + if ((pBatch->batchSize + pMsg->msg.contLen) < (*ppBatchList)->batchLenLimit) { + QUEUE_PUSH(&pBatch->wq, h); + pBatch->batchSize += pMsg->msg.contLen; + pBatch->wLen += 1; + } else { + SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); + QUEUE_INIT(&pBatch->wq); + QUEUE_INIT(&pBatch->listq); + + QUEUE_PUSH(&pBatch->wq, h); + pBatch->wLen += 1; + pBatch->batchSize += pMsg->msg.contLen; + pBatch->pList = *ppBatchList; + + QUEUE_PUSH(&((*ppBatchList)->wq), &pBatch->listq); + (*ppBatchList)->len += 1; + } + } + return; +} static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { STrans* pInst = pThrd->pTransInst; @@ -1746,75 +1817,7 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { } if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { - STransConnCtx* pCtx = pMsg->ctx; - - char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet); - uint32_t port = EPSET_GET_INUSE_PORT(&pCtx->epSet); - char key[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(key, ip, port); - size_t klen = strlen(key); - SCliBatchList** ppBatchList = taosHashGet(pThrd->batchCache, key, klen); - if (ppBatchList == NULL || *ppBatchList == NULL) { - SCliBatchList* pBatchList = taosMemoryCalloc(1, sizeof(SCliBatchList)); - QUEUE_INIT(&pBatchList->wq); - pBatchList->connMax = pInst->connLimitNum; - pBatchList->connCnt = 0; - pBatchList->batchLenLimit = pInst->batchSize; - pBatchList->len += 1; - - pBatchList->ip = taosStrdup(ip); - pBatchList->dst = taosStrdup(key); - pBatchList->port = port; - - SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); - QUEUE_INIT(&pBatch->wq); - QUEUE_INIT(&pBatch->listq); - - QUEUE_PUSH(&pBatch->wq, h); - pBatch->wLen += 1; - pBatch->batchSize += pMsg->msg.contLen; - pBatch->pList = pBatchList; - - QUEUE_PUSH(&pBatchList->wq, &pBatch->listq); - - taosHashPut(pThrd->batchCache, key, klen, &pBatchList, sizeof(void*)); - } else { - if (QUEUE_IS_EMPTY(&(*ppBatchList)->wq)) { - SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); - QUEUE_INIT(&pBatch->wq); - QUEUE_INIT(&pBatch->listq); - - QUEUE_PUSH(&pBatch->wq, h); - pBatch->wLen += 1; - pBatch->batchSize = pMsg->msg.contLen; - pBatch->pList = *ppBatchList; - - QUEUE_PUSH(&((*ppBatchList)->wq), &pBatch->listq); - (*ppBatchList)->len += 1; - - continue; - } - - queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); - SCliBatch* pBatch = QUEUE_DATA(hdr, SCliBatch, listq); - if ((pBatch->batchSize + pMsg->msg.contLen) < (*ppBatchList)->batchLenLimit) { - QUEUE_PUSH(&pBatch->wq, h); - pBatch->batchSize += pMsg->msg.contLen; - pBatch->wLen += 1; - } else { - SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); - QUEUE_INIT(&pBatch->wq); - QUEUE_INIT(&pBatch->listq); - - QUEUE_PUSH(&pBatch->wq, h); - pBatch->wLen += 1; - pBatch->batchSize += pMsg->msg.contLen; - pBatch->pList = *ppBatchList; - - QUEUE_PUSH(&((*ppBatchList)->wq), &pBatch->listq); - (*ppBatchList)->len += 1; - } - } + cliBuildBatch(pMsg, h, pThrd); continue; } (*cliAsyncHandle[pMsg->type])(pMsg, pThrd); @@ -1847,12 +1850,7 @@ static void cliAsyncCb(uv_async_t* handle) { QUEUE_MOVE(&item->qmsg, &wq); taosThreadMutexUnlock(&item->mtx); - int8_t supportBatch = pTransInst->supportBatch; - if (supportBatch == 0) { - cliNoBatchDealReq(&wq, pThrd); - } else if (supportBatch == 1) { - cliBatchDealReq(&wq, pThrd); - } + cliDealFunc[pTransInst->supportBatch](&wq, pThrd); if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd); } From 19327071370e596eb8cc6842f8a61863ba222466 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Tue, 7 May 2024 03:28:31 +0000 Subject: [PATCH 003/240] refactor transport --- source/libs/stream/src/streamBackendRocksdb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 358795a4a2..fe9d78d8f9 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -2775,6 +2775,9 @@ int32_t streamStateGetKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, cons size_t vlen = 0; const char* valStr = rocksdb_iter_value(pCur->iter, &vlen); *pVLen = valueDecode((void*)valStr, vlen, NULL, (char**)pVal); + if (*pVLen < 0) { + return -1; + } } *pKey = pKtmp->key; From 4d3be8129e869c1191d58c92bd8e38dcffefddcd Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 8 May 2024 01:01:42 +0000 Subject: [PATCH 004/240] refactor transport --- source/libs/transport/src/transCli.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 86d6ef58ff..98467b5c09 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1777,6 +1777,7 @@ static void cliBuildBatch(SCliMsg* pMsg, queue* h, SCliThrd* pThrd) { QUEUE_PUSH(&((*ppBatchList)->wq), &pBatch->listq); (*ppBatchList)->len += 1; + return; } queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); From 29215d2411eba4575e78e7bd3a7ef39c77d4ba38 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 8 May 2024 10:16:10 +0000 Subject: [PATCH 005/240] refactor transport --- source/libs/transport/src/transCli.c | 14 ++++---------- source/libs/transport/src/transSvr.c | 3 ++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 98467b5c09..97a15c7fc8 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -113,7 +113,6 @@ typedef struct SCliThrd { uint64_t nextTimeout; // next timeout void* pTransInst; // - int connCount; void (*destroyAhandleFp)(void* ahandle); SHashObj* fqdn2ipCache; SCvtAddr cvtAddr; @@ -915,7 +914,6 @@ static SCliConn* cliCreateConn(SCliThrd* pThrd) { conn->broken = false; transRefCliHandle(conn); - atomic_add_fetch_32(&pThrd->connCount, 1); allocConnRef(conn, false); return conn; @@ -977,8 +975,6 @@ static void cliDestroy(uv_handle_t* handle) { conn->timer = NULL; } - atomic_sub_fetch_32(&pThrd->connCount, 1); - transReleaseExHandle(transGetRefMgt(), conn->refId); transRemoveExHandle(transGetRefMgt(), conn->refId); taosMemoryFree(conn->dstAddr); @@ -2002,10 +1998,8 @@ static FORCE_INLINE void destroyCmsg(void* arg) { taosMemoryFree(pMsg); } static FORCE_INLINE void destroyCmsgWrapper(void* arg, void* param) { + if (arg == NULL) return; SCliMsg* pMsg = arg; - if (pMsg == NULL) { - return; - } SCliThrd* pThrd = param; if (pMsg->msg.info.notFreeAhandle == 0 && pThrd != NULL) { @@ -2335,9 +2329,9 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { // code, msgType - // A: epset, leader, not self - // B: epset, not know leader - // C: no epset, leader but not serivce + // A: epset,leader, not self + // B: epset,not know leader + // C: noepset,leader but not serivce bool noDelay = false; if (code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 21ad5be869..d47968eeb8 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -676,7 +676,8 @@ static FORCE_INLINE void destroySmsg(SSvrMsg* smsg) { taosMemoryFree(smsg); } static FORCE_INLINE void destroySmsgWrapper(void* smsg, void* param) { destroySmsg((SSvrMsg*)smsg); } -static void destroyAllConn(SWorkThrd* pThrd) { + +static void destroyAllConn(SWorkThrd* pThrd) { tTrace("thread %p destroy all conn ", pThrd); while (!QUEUE_IS_EMPTY(&pThrd->conn)) { queue* h = QUEUE_HEAD(&pThrd->conn); From 77c7ee264c11e22f826aac50537896e79a5522b0 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 16 May 2024 11:42:14 +0800 Subject: [PATCH 006/240] refactor transport --- source/libs/transport/src/transCli.c | 95 +++++++++++++--------------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 97a15c7fc8..419c037a5d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -175,6 +175,7 @@ static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); static int32_t allocConnRef(SCliConn* conn, bool update); static int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg); +void cliResetConnTimer(SCliConn* conn); static SCliConn* cliCreateConn(SCliThrd* thrd); static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); @@ -367,10 +368,8 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { return false; } -void cliHandleResp(SCliConn* conn) { +void cliResetConnTimer(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; - if (conn->timer) { if (uv_is_active((uv_handle_t*)conn->timer)) { tDebug("%s conn %p stop timer", CONN_GET_INST_LABEL(conn), conn); @@ -380,6 +379,40 @@ void cliHandleResp(SCliConn* conn) { conn->timer->data = NULL; conn->timer = NULL; } +} +void cliHandleBatchResp(SCliConn* conn) { + SCliThrd* pThrd = conn->hostThrd; + STrans* pTransInst = pThrd->pTransInst; + cliResetConnTimer(conn); + + STransMsgHead* pHead = NULL; + int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead); + if (transDecompressMsg((char**)&pHead, msgLen) < 0) { + tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); + } + pHead->code = htonl(pHead->code); + pHead->msgLen = htonl(pHead->msgLen); + + STransMsg transMsg = {0}; + transMsg.contLen = transContLenFromMsg(pHead->msgLen); + transMsg.pCont = transContFromHead((char*)pHead); + transMsg.code = pHead->code; + transMsg.msgType = pHead->msgType; + transMsg.info.ahandle = NULL; + transMsg.info.traceId = pHead->traceId; + transMsg.info.hasEpSet = pHead->hasEpSet; + transMsg.info.cliVer = htonl(pHead->compatibilityVer); + + SCliMsg* pMsg = NULL; + STransConnCtx* pCtx = pMsg->ctx; + if (cliAppCb(conn, &transMsg, pMsg) != 0) { + return; + } +} +void cliHandleResp(SCliConn* conn) { + SCliThrd* pThrd = conn->hostThrd; + STrans* pTransInst = pThrd->pTransInst; + cliResetConnTimer(conn); STransMsgHead* pHead = NULL; @@ -578,11 +611,7 @@ 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); - handle->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); - conn->timer = NULL; - + cliResetConnTimer(conn); cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); cliHandleFastFail(conn, UV_ECANCELED); } @@ -757,12 +786,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { allocConnRef(conn, true); SCliThrd* thrd = conn->hostThrd; - if (conn->timer != NULL) { - uv_timer_stop(conn->timer); - taosArrayPush(thrd->timerList, &conn->timer); - conn->timer->data = NULL; - conn->timer = NULL; - } + cliResetConnTimer(conn); if (T_REF_VAL_GET(conn) > 1) { transUnrefCliHandle(conn); } @@ -948,12 +972,7 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { transDQCancel(pThrd->timeoutQueue, conn->task); conn->task = NULL; } - if (conn->timer != NULL) { - uv_timer_stop(conn->timer); - conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); - conn->timer = NULL; - } + cliResetConnTimer(conn); if (clear) { if (!uv_is_closing((uv_handle_t*)conn->stream)) { @@ -968,12 +987,7 @@ 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); - conn->timer->data = NULL; - conn->timer = NULL; - } + cliResetConnTimer(conn); transReleaseExHandle(transGetRefMgt(), conn->refId); transRemoveExHandle(transGetRefMgt(), conn->refId); @@ -1230,11 +1244,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, pList->ip); if (ipaddr == 0xffffffff) { - uv_timer_stop(conn->timer); - conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); - conn->timer = NULL; - + cliResetConnTimer(conn); cliHandleFastFail(conn, -1); return; } @@ -1266,11 +1276,7 @@ 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); - conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); - conn->timer = NULL; - + cliResetConnTimer(conn); cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); cliHandleFastFail(conn, -1); return; @@ -1366,10 +1372,7 @@ void cliConnCb(uv_connect_t* req, int status) { if (pConn->timer == NULL) { timeout = true; } else { - uv_timer_stop(pConn->timer); - pConn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &pConn->timer); - pConn->timer = NULL; + cliResetConnTimer(pConn); } if (status != 0) { @@ -1641,11 +1644,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn); if (ipaddr == 0xffffffff) { - uv_timer_stop(conn->timer); - conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); - conn->timer = NULL; - + cliResetConnTimer(conn); cliHandleExcept(conn); return; } @@ -1679,11 +1678,7 @@ 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); - conn->timer->data = NULL; - taosArrayPush(pThrd->timerList, &conn->timer); - conn->timer = NULL; - + cliResetConnTimer(conn); cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); cliHandleFastFail(conn, ret); return; From 81a4ef73f1121d8b74e166ab42d455b6fe2a1ceb Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 16 May 2024 16:26:49 +0800 Subject: [PATCH 007/240] refactor transport --- source/libs/transport/src/transCli.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 419c037a5d..023cb16b8b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1803,13 +1803,13 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - if (pMsg->type == Quit) { - pThrd->stopMsg = pMsg; + if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { + cliBuildBatch(pMsg, h, pThrd); continue; } - if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { - cliBuildBatch(pMsg, h, pThrd); + if (pMsg->type == Quit) { + pThrd->stopMsg = pMsg; continue; } (*cliAsyncHandle[pMsg->type])(pMsg, pThrd); From a0abe6743271db820b10189182233659ab553220 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 23 May 2024 06:49:24 +0000 Subject: [PATCH 008/240] refactor tranport --- source/libs/transport/inc/transportInt.h | 1 + source/libs/transport/src/transCli.c | 105 ++++++++++++----------- 2 files changed, 57 insertions(+), 49 deletions(-) diff --git a/source/libs/transport/inc/transportInt.h b/source/libs/transport/inc/transportInt.h index 7853e25cff..232210b53b 100644 --- a/source/libs/transport/inc/transportInt.h +++ b/source/libs/transport/inc/transportInt.h @@ -69,6 +69,7 @@ typedef struct { int8_t connLimitLock; // 0: no lock. 1. lock int8_t supportBatch; // 0: no batch, 1: support batch int32_t batchSize; + int8_t optBatchFetch; int32_t timeToGetConn; int index; void* parent; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 023cb16b8b..f6e4c4ecf9 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1213,23 +1213,67 @@ static void cliDestroyBatch(SCliBatch* pBatch) { p->sending -= 1; taosMemoryFree(pBatch); } + +static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { + STrans* pTransInst = pThrd->pTransInst; + uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, ip); + if (ipaddr == 0xffffffff) { + cliResetConnTimer(conn); + cliHandleFastFail(conn, -1); + return; + } + + struct sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = ipaddr; + addr.sin_port = (uint16_t)htons(port); + + tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, conn->dstAddr); + int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); + if (fd == -1) { + tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, + tstrerror(TAOS_SYSTEM_ERROR(errno))); + cliHandleFastFail(conn, -1); + return; + } + int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); + if (ret != 0) { + tError("%s conn %p failed to set stream, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); + cliHandleFastFail(conn, -1); + return; + } + ret = transSetConnOption((uv_tcp_t*)conn->stream, 20); + if (ret != 0) { + tError("%s conn %p failed to set socket opt, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); + cliHandleFastFail(conn, -1); + return; + } + + ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); + if (ret != 0) { + cliResetConnTimer(conn); + cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); + cliHandleFastFail(conn, -1); + return; + } + uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + return; +} static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { + if (pBatch == NULL || pBatch->wLen == 0 || QUEUE_IS_EMPTY(&pBatch->wq)) { + return; + } + if (pThrd->quit == true) { cliDestroyBatch(pBatch); return; } - if (pBatch == NULL || pBatch->wLen == 0 || QUEUE_IS_EMPTY(&pBatch->wq)) { - return; - } STrans* pTransInst = pThrd->pTransInst; SCliBatchList* pList = pBatch->pList; - char key[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(key, pList->ip, pList->port); - bool exceed = false; - SCliConn* conn = getConnFromPool(pThrd, key, &exceed); + SCliConn* conn = getConnFromPool(pThrd, pList->dst, &exceed); if (conn == NULL && exceed) { tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d", pTransInst->label, pBatch->wLen, @@ -1241,48 +1285,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { conn = cliCreateConn(pThrd); conn->pBatch = pBatch; conn->dstAddr = taosStrdup(pList->dst); - - uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, pList->ip); - if (ipaddr == 0xffffffff) { - cliResetConnTimer(conn); - cliHandleFastFail(conn, -1); - return; - } - struct sockaddr_in addr; - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = ipaddr; - addr.sin_port = (uint16_t)htons(pList->port); - - tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, pList->dst); - int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); - if (fd == -1) { - tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, - tstrerror(TAOS_SYSTEM_ERROR(errno))); - cliHandleFastFail(conn, -1); - return; - } - int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); - if (ret != 0) { - tError("%s conn %p failed to set stream, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); - cliHandleFastFail(conn, -1); - return; - } - ret = transSetConnOption((uv_tcp_t*)conn->stream, 20); - if (ret != 0) { - tError("%s conn %p failed to set socket opt, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); - cliHandleFastFail(conn, -1); - return; - } - - ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); - if (ret != 0) { - cliResetConnTimer(conn); - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, -1); - return; - } - uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); - return; + return cliDoConn(pThrd, conn, pList->ip, pList->port); } conn->pBatch = pBatch; @@ -1803,6 +1806,10 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); + if (pMsg->type == Normal) { + cliBuildBatch(pMsg, h, pThrd); + count++; + } if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { cliBuildBatch(pMsg, h, pThrd); continue; From 1685fab216108a03ddaeb93afdfa4211c80889d5 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 23 May 2024 07:58:15 +0000 Subject: [PATCH 009/240] refactor tranport --- source/libs/transport/src/transCli.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f6e4c4ecf9..5c1b970ceb 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1806,10 +1806,11 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - if (pMsg->type == Normal) { - cliBuildBatch(pMsg, h, pThrd); - count++; - } + // if (pMsg->type == Normal) { + // cliBuildBatch(pMsg, h, pThrd); + // continue; + // // count++; + // } if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { cliBuildBatch(pMsg, h, pThrd); continue; From 2cdaa8c96246b765135eeb12b74e3d7fa1d309c9 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 29 May 2024 09:19:27 +0000 Subject: [PATCH 010/240] opt transport --- include/libs/transport/trpc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 95f70c8ff3..e6b59fd814 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -126,6 +126,7 @@ typedef struct SRpcInit { int32_t timeToGetConn; int8_t supportBatch; // 0: no batch, 1. batch int32_t batchSize; + int8_t shareConn; // 0: no share, 1. share void *parent; } SRpcInit; From 9138ea4cec30269359a007f18c990183e2b99a3c Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 29 May 2024 09:20:30 +0000 Subject: [PATCH 011/240] opt transport --- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 1 + source/dnode/vnode/src/vnd/vnodeSvr.c | 14 +- source/libs/transport/inc/transportInt.h | 1 + source/libs/transport/src/trans.c | 2 + source/libs/transport/src/transCli.c | 209 +++++++++++++++++- 5 files changed, 217 insertions(+), 10 deletions(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index a2355ddd22..f4e6d42e60 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -372,6 +372,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; rpcInit.batchSize = 8 * 1024; + rpcInit.shareConn = 1; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 6d97c1cd79..6438601937 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -50,7 +50,7 @@ static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t l static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token); static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token); -static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode* pVnode, int64_t ver, void* pReq, int32_t len, SRpcMsg* pRsp); +static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp); extern int32_t vnodeProcessKillCompactReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp); extern int32_t vnodeQueryCompactProgress(SVnode *pVnode, SRpcMsg *pMsg); @@ -931,13 +931,13 @@ end: return ret; } -static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode* pVnode, int64_t ver, void* pReq, int32_t len, SRpcMsg* pRsp) { +static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { int32_t code = -1; SMetaReader mr = {0}; SVDropTtlTableReq ttlReq = {0}; SVFetchTtlExpiredTbsRsp rsp = {0}; SEncoder encoder = {0}; - SArray* pNames = NULL; + SArray *pNames = NULL; pRsp->msgType = TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP; pRsp->code = TSDB_CODE_SUCCESS; pRsp->pCont = NULL; @@ -950,8 +950,8 @@ static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode* pVnode, int64_t ver, void* ASSERT(ttlReq.nUids == taosArrayGetSize(ttlReq.pTbUids)); - tb_uid_t suid; - char ctbName[TSDB_TABLE_NAME_LEN]; + tb_uid_t suid; + char ctbName[TSDB_TABLE_NAME_LEN]; SVDropTbReq expiredTb = {.igNotExists = true}; metaReaderDoInit(&mr, pVnode->pMeta, 0); rsp.vgId = TD_VID(pVnode); @@ -965,12 +965,12 @@ static int32_t vnodeProcessFetchTtlExpiredTbs(SVnode* pVnode, int64_t ver, void* } char buf[TSDB_TABLE_NAME_LEN]; for (int32_t i = 0; i < ttlReq.nUids; ++i) { - tb_uid_t* uid = taosArrayGet(ttlReq.pTbUids, i); + tb_uid_t *uid = taosArrayGet(ttlReq.pTbUids, i); expiredTb.suid = *uid; terrno = metaReaderGetTableEntryByUid(&mr, *uid); if (terrno < 0) goto _end; strncpy(buf, mr.me.name, TSDB_TABLE_NAME_LEN); - void* p = taosArrayPush(pNames, buf); + void *p = taosArrayPush(pNames, buf); expiredTb.name = p; if (mr.me.type == TSDB_CHILD_TABLE) { expiredTb.suid = mr.me.ctbEntry.suid; diff --git a/source/libs/transport/inc/transportInt.h b/source/libs/transport/inc/transportInt.h index 232210b53b..8e8672a357 100644 --- a/source/libs/transport/inc/transportInt.h +++ b/source/libs/transport/inc/transportInt.h @@ -75,6 +75,7 @@ typedef struct { void* parent; void* tcphandle; // returned handle from TCP initialization int64_t refId; + int8_t shareConn; TdThreadMutex mutex; } SRpcInfo; diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 5ed2e00acd..4bfd0c0805 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -112,6 +112,8 @@ void* rpcOpen(const SRpcInit* pInit) { int64_t refId = transAddExHandle(transGetInstMgt(), pRpc); transAcquireExHandle(transGetInstMgt(), refId); pRpc->refId = refId; + + pRpc->shareConn = pInit->shareConn; return (void*)refId; } void rpcClose(void* arg) { diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 5c1b970ceb..e59065ef26 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -76,6 +76,9 @@ typedef struct SCliConn { SDelayTask* task; + HeapNode node; // for heap + int8_t inHeap; + char* dstAddr; char src[32]; char dst[32]; @@ -119,6 +122,7 @@ typedef struct SCliThrd { SHashObj* failFastCache; SHashObj* batchCache; + SHashObj* connHeapCache; SCliMsg* stopMsg; bool quit; @@ -230,6 +234,23 @@ static void destroyThrdObj(SCliThrd* pThrd); static void cliWalkCb(uv_handle_t* handle, void* arg); +typedef struct { + void* p; + HeapNode node; +} SHeapNode; +typedef struct { + // void* p; + Heap* heap; + int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b); +} SHeap; + +int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); +int transHeapCreate(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); +void transHeapDestroy(SHeap* heap); +void transHeapGet(SHeap* heap, SCliConn** p); +int transHeapInsert(SHeap* heap, SCliConn* p); +int transHeapDelete(SHeap* heap, SCliConn* p); + #define CLI_RELEASE_UV(loop) \ do { \ uv_walk(loop, cliWalkCb, NULL); \ @@ -1054,6 +1075,66 @@ static void cliSendCb(uv_write_t* req, int status) { } uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); } + +void cliSendBatch_shareConn(SCliConn* pConn) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pTransInst = pThrd->pTransInst; + int32_t size = transQueueSize(&pConn->cliMsgs); + int32_t totalLen = 0; + if (size == 0) { + tError("%s conn %p not msg to send", pTransInst->label, pConn); + cliHandleExcept(pConn); + return; + } + uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); + + for (int i = 0; i < size; i++) { + SCliMsg* pCliMsg = transQueueGet(&pConn->cliMsgs, i); + + STransConnCtx* pCtx = pCliMsg->ctx; + + STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg); + if (pMsg->pCont == 0) { + pMsg->pCont = (void*)rpcMallocCont(0); + pMsg->contLen = 0; + } + + int msgLen = transMsgLenFromCont(pMsg->contLen); + STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); + + if (pHead->comp == 0) { + pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; + pHead->noResp = REQUEST_NO_RESP(pMsg) ? 1 : 0; + pHead->persist = REQUEST_PERSIS_HANDLE(pMsg) ? 1 : 0; + pHead->msgType = pMsg->msgType; + pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); + pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; + memcpy(pHead->user, pTransInst->user, strlen(pTransInst->user)); + pHead->traceId = pMsg->info.traceId; + pHead->magicNum = htonl(TRANS_MAGIC_NUM); + pHead->version = TRANS_VER; + pHead->compatibilityVer = htonl(pTransInst->compatibilityVer); + } + pHead->timestamp = taosHton64(taosGetTimestampUs()); + + if (pHead->comp == 0) { + if (pTransInst->compressSize != -1 && pTransInst->compressSize < pMsg->contLen) { + msgLen = transCompressMsg(pMsg->pCont, pMsg->contLen) + sizeof(STransMsgHead); + pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); + } + } else { + msgLen = (int32_t)ntohl((uint32_t)(pHead->msgLen)); + } + wb[i++] = uv_buf_init((char*)pHead, msgLen); + totalLen += msgLen; + } + uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); + req->data = pConn; + tDebug("%s conn %p start to send batch msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, + totalLen); + uv_write(req, (uv_stream_t*)pConn->stream, wb, size, cliSendBatchCb); + taosMemoryFree(wb); +} void cliSendBatch(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pTransInst = pThrd->pTransInst; @@ -1399,10 +1480,13 @@ void cliConnCb(uv_connect_t* req, int status) { tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); if (pConn->pBatch != NULL) { - cliSendBatch(pConn); - } else { - cliSend(pConn); + return cliSendBatch(pConn); } + if (pConn->inHeap) { + return cliSendBatch_shareConn(pConn); + } + + return cliSend(pConn); } static void doNotifyApp(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code) { @@ -1596,9 +1680,68 @@ static void doFreeTimeoutMsg(void* param) { doNotifyApp(pMsg, pThrd, code); taosMemoryFree(arg); } + +static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { + size_t klen = strlen(key); + SHeap* p = taosHashGet(pConnHeapCache, key, klen); + if (p == NULL) { + SHeap heap = {0}; + transHeapCreate(&heap, compareHeapNode); + taosHashPut(pConnHeapCache, key, klen, &heap, sizeof(heap)); + + p = taosHashGet(pConnHeapCache, key, strlen(key)); + return NULL; + } + SCliConn* pConn = NULL; + transHeapGet(p, &pConn); + return pConn; +} +static void addConnToHeapCache(SHashObj* pConnHeapCacahe, char* key, SCliConn* pConn) { + size_t klen = strlen(key); + SHeap* p = taosHashGet(pConnHeapCacahe, key, klen); + if (p == NULL) { + SHeap heap = {0}; + transHeapCreate(&heap, compareHeapNode); + taosHashPut(pConnHeapCacahe, key, klen, &heap, sizeof(heap)); + p = taosHashGet(pConnHeapCacahe, key, klen); + } + transHeapInsert(p, pConn); +} +void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { + STraceId* trace = &pMsg->msg.info.traceId; + + STrans* pTransInst = pThrd->pTransInst; + + cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); + if (!EPSET_IS_VALID(&pMsg->ctx->epSet)) { + destroyCmsg(pMsg); + return; + } + char addr[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); + + SCliConn* pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); + if (pConn == NULL) { + tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); + bool ignore = false; + pConn = getConnFromPool(pThrd, addr, &ignore); + if (pConn != NULL) { + return cliSendBatch_shareConn(pConn); + } + } + + pConn = cliCreateConn(pThrd); + addConnToHeapCache(pThrd->connHeapCache, addr, pConn); + + return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); +} void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { STrans* pTransInst = pThrd->pTransInst; + if (pTransInst->shareConn == 1) { + return cliHandleReq__shareConn(pMsg, pThrd); + } + cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); if (!EPSET_IS_VALID(&pMsg->ctx->epSet)) { destroyCmsg(pMsg); @@ -2083,6 +2226,7 @@ static SCliThrd* createThrdObj(void* trans) { pThrd->failFastCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pThrd->batchCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + pThrd->connHeapCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pThrd->quit = false; @@ -2131,6 +2275,15 @@ static void destroyThrdObj(SCliThrd* pThrd) { pIter = (void**)taosHashIterate(pThrd->batchCache, pIter); } taosHashCleanup(pThrd->batchCache); + + void** pIter2 = taosHashIterate(pThrd->connHeapCache, NULL); + while (pIter2 != NULL) { + SHeap* heap = (SHeap*)(*pIter2); + transHeapDestroy(heap); + pIter2 = (void**)taosHashIterate(pThrd->connHeapCache, pIter2); + } + taosHashCleanup(pThrd->connHeapCache); + taosMemoryFree(pThrd); } @@ -2800,3 +2953,53 @@ int64_t transAllocHandle() { return exh->refId; } + +int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { + SCliConn* args1 = container_of(a, SCliConn, node); + SCliConn* args2 = container_of(b, SCliConn, node); + if (transQueueSize(&args1->cliMsgs) > transQueueSize(&args2->cliMsgs)) { + return 0; + } + return 1; +} +int transHeapCreate(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)) { + heap->heap = heapCreate(cmpFunc); + heap->cmpFunc = cmpFunc; + return 0; +} +void transHeapDestroy(SHeap* heap) { + if (heap != NULL) { + heapDestroy(heap->heap); + } +} +void transHeapGet(SHeap* heap, SCliConn** p) { + if (heapSize(heap->heap) == 0) { + *p = NULL; + return; + } + // HeapNode* minNode = headMin(heap->heap); + HeapNode* minNode = heapMin(heap->heap); + if (minNode == NULL) { + *p = NULL; + return; + } + *p = container_of(minNode, SCliConn, node); +} +int transHeapInsert(SHeap* heap, SCliConn* p) { + // impl later + if (p->inHeap == 1) { + return -1; + } + + heapInsert(heap->heap, &p->node); + p->inHeap = 1; + return 0; +} +int transHeapDelete(SHeap* heap, SCliConn* p) { + // impl later + if (p->inHeap == 0) { + return -1; + } + heapRemove(heap->heap, &p->node); + return 0; +} \ No newline at end of file From 5c191e790f41461e16fa471ff37ddc2743190255 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 30 May 2024 02:09:11 +0000 Subject: [PATCH 012/240] opt transport --- source/libs/transport/src/transCli.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e59065ef26..a065b5dc2a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1076,6 +1076,19 @@ static void cliSendCb(uv_write_t* req, int status) { uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); } +static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { + SCliConn* conn = req->data; + SCliThrd* thrd = conn->hostThrd; + if (status != 0) { + tDebug("%s conn %p failed to send batch msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); + if (!uv_is_closing((uv_handle_t*)&conn->stream)) { + cliHandleExcept(conn); + } + return; + } + uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + taosMemoryFree(req); +} void cliSendBatch_shareConn(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pTransInst = pThrd->pTransInst; @@ -1132,7 +1145,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { req->data = pConn; tDebug("%s conn %p start to send batch msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); - uv_write(req, (uv_stream_t*)pConn->stream, wb, size, cliSendBatchCb); + uv_write(req, (uv_stream_t*)pConn->stream, wb, size, cliSendBatch_shareConnCb); taosMemoryFree(wb); } void cliSendBatch(SCliConn* pConn) { From 3cf063e1357e266be7f98ba4d09534ae10d7522c Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 12 Jun 2024 01:40:26 +0000 Subject: [PATCH 013/240] fix merge error --- source/libs/transport/src/transCli.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a065b5dc2a..d075ace7d5 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -247,7 +247,7 @@ typedef struct { int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); int transHeapCreate(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); void transHeapDestroy(SHeap* heap); -void transHeapGet(SHeap* heap, SCliConn** p); +int transHeapGet(SHeap* heap, SCliConn** p); int transHeapInsert(SHeap* heap, SCliConn* p); int transHeapDelete(SHeap* heap, SCliConn* p); @@ -1701,8 +1701,6 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { SHeap heap = {0}; transHeapCreate(&heap, compareHeapNode); taosHashPut(pConnHeapCache, key, klen, &heap, sizeof(heap)); - - p = taosHashGet(pConnHeapCache, key, strlen(key)); return NULL; } SCliConn* pConn = NULL; @@ -2985,18 +2983,19 @@ void transHeapDestroy(SHeap* heap) { heapDestroy(heap->heap); } } -void transHeapGet(SHeap* heap, SCliConn** p) { +int transHeapGet(SHeap* heap, SCliConn** p) { if (heapSize(heap->heap) == 0) { *p = NULL; - return; + return -1; } // HeapNode* minNode = headMin(heap->heap); HeapNode* minNode = heapMin(heap->heap); if (minNode == NULL) { *p = NULL; - return; + return -1; } *p = container_of(minNode, SCliConn, node); + return 0; } int transHeapInsert(SHeap* heap, SCliConn* p) { // impl later From e9c358c9d4e45868fc2ee8709876d475c701b73d Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Fri, 14 Jun 2024 12:57:28 +0000 Subject: [PATCH 014/240] refactor transport --- source/libs/transport/inc/transComm.h | 1 + source/libs/transport/src/transCli.c | 167 +++++++++++++++++++------- source/libs/transport/src/transComm.c | 4 - source/libs/transport/src/transSvr.c | 111 +++++++++-------- 4 files changed, 181 insertions(+), 102 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index da6d71e07b..9119ae083c 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -187,6 +187,7 @@ typedef struct { uint32_t code; // del later uint32_t msgType; int32_t msgLen; + int32_t seqNum; uint8_t content[0]; // message body starts from here } STransMsgHead; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d075ace7d5..8ec54167af 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -84,6 +84,7 @@ typedef struct SCliConn { char dst[32]; int64_t refId; + int32_t seq; } SCliConn; typedef struct SCliMsg { @@ -96,6 +97,7 @@ typedef struct SCliMsg { uint64_t st; int sent; //(0: no send, 1: alread sent) queue seqq; + int32_t seqNum; } SCliMsg; typedef struct SCliThrd { @@ -402,6 +404,7 @@ void cliResetConnTimer(SCliConn* conn) { } } void cliHandleBatchResp(SCliConn* conn) { + ASSERT(0); SCliThrd* pThrd = conn->hostThrd; STrans* pTransInst = pThrd->pTransInst; cliResetConnTimer(conn); @@ -430,9 +433,70 @@ void cliHandleBatchResp(SCliConn* conn) { return; } } + +SCliMsg* cliFindMsgBySeqnum(SCliConn* conn, int32_t seqNum) { + SCliMsg* pMsg = NULL; + for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) { + pMsg = transQueueGet(&conn->cliMsgs, i); + if (pMsg->seqNum == seqNum) { + transQueueRm(&conn->cliMsgs, i); + break; + } + } + if (pMsg == NULL) { + ASSERT(0); + } + return pMsg; +} +void cliHandleResp_shareConn(SCliConn* conn) { + SCliThrd* pThrd = conn->hostThrd; + STrans* pTransInst = pThrd->pTransInst; + cliResetConnTimer(conn); + + STransMsgHead* pHead = NULL; + int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead); + + if (msgLen <= 0) { + taosMemoryFree(pHead); + tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); + return; + } + if (transDecompressMsg((char**)&pHead, msgLen) < 0) { + tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); + } + pHead->code = htonl(pHead->code); + pHead->msgLen = htonl(pHead->msgLen); + + STransMsg transMsg = {0}; + transMsg.contLen = transContLenFromMsg(pHead->msgLen); + transMsg.pCont = transContFromHead((char*)pHead); + transMsg.code = pHead->code; + transMsg.msgType = pHead->msgType; + transMsg.info.ahandle = NULL; + transMsg.info.traceId = pHead->traceId; + transMsg.info.hasEpSet = pHead->hasEpSet; + transMsg.info.cliVer = htonl(pHead->compatibilityVer); + + SCliMsg* pMsg = cliFindMsgBySeqnum(conn, pHead->seqNum); + pMsg->seqNum = 0; + + STransConnCtx* pCtx = pMsg->ctx; + transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; + STraceId* trace = &transMsg.info.traceId; + + if (cliAppCb(conn, &transMsg, pMsg) != 0) { + return; + } + + return; +} void cliHandleResp(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pTransInst = pThrd->pTransInst; + + if (pTransInst->shareConn) { + return cliHandleResp_shareConn(conn); + } cliResetConnTimer(conn); STransMsgHead* pHead = NULL; @@ -716,6 +780,7 @@ static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) { transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); conn->task = NULL; } + conn->seq++; return conn; } @@ -813,6 +878,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { } cliDestroyConnMsgs(conn, false); + conn->seq = 0; if (conn->list == NULL) { conn->list = taosHashGet((SHashObj*)pool, conn->dstAddr, strlen(conn->dstAddr)); @@ -871,6 +937,7 @@ static int32_t allocConnRef(SCliConn* conn, bool update) { } static int32_t specifyConnRef(SCliConn* conn, bool update, int64_t handle) { + if (handle == 0) return -1; if (update) { transReleaseExHandle(transGetRefMgt(), conn->refId); transRemoveExHandle(transGetRefMgt(), conn->refId); @@ -958,7 +1025,7 @@ static SCliConn* cliCreateConn(SCliThrd* pThrd) { conn->status = ConnNormal; conn->broken = false; transRefCliHandle(conn); - + conn->seq = 0; allocConnRef(conn, false); return conn; @@ -1078,7 +1145,6 @@ static void cliSendCb(uv_write_t* req, int status) { static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { SCliConn* conn = req->data; - SCliThrd* thrd = conn->hostThrd; if (status != 0) { tDebug("%s conn %p failed to send batch msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); if (!uv_is_closing((uv_handle_t*)&conn->stream)) { @@ -1093,7 +1159,8 @@ void cliSendBatch_shareConn(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pTransInst = pThrd->pTransInst; int32_t size = transQueueSize(&pConn->cliMsgs); - int32_t totalLen = 0; + + int32_t totalLen = 0; if (size == 0) { tError("%s conn %p not msg to send", pTransInst->label, pConn); cliHandleExcept(pConn); @@ -1101,10 +1168,14 @@ void cliSendBatch_shareConn(SCliConn* pConn) { } uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); + int j = 0; for (int i = 0; i < size; i++) { SCliMsg* pCliMsg = transQueueGet(&pConn->cliMsgs, i); - + if (pCliMsg->sent == 1) { + continue; + } STransConnCtx* pCtx = pCliMsg->ctx; + pConn->seq++; STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg); if (pMsg->pCont == 0) { @@ -1112,7 +1183,8 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pMsg->contLen = 0; } - int msgLen = transMsgLenFromCont(pMsg->contLen); + int msgLen = transMsgLenFromCont(pMsg->contLen); + STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); if (pHead->comp == 0) { @@ -1129,6 +1201,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pHead->compatibilityVer = htonl(pTransInst->compatibilityVer); } pHead->timestamp = taosHton64(taosGetTimestampUs()); + pHead->seqNum = pConn->seq; if (pHead->comp == 0) { if (pTransInst->compressSize != -1 && pTransInst->compressSize < pMsg->contLen) { @@ -1138,14 +1211,17 @@ void cliSendBatch_shareConn(SCliConn* pConn) { } else { msgLen = (int32_t)ntohl((uint32_t)(pHead->msgLen)); } - wb[i++] = uv_buf_init((char*)pHead, msgLen); + wb[j++] = uv_buf_init((char*)pHead, msgLen); totalLen += msgLen; + + pCliMsg->sent = 1; + pCliMsg->seqNum = pHead->seqNum; } uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); req->data = pConn; tDebug("%s conn %p start to send batch msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); - uv_write(req, (uv_stream_t*)pConn->stream, wb, size, cliSendBatch_shareConnCb); + uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliSendBatch_shareConnCb); taosMemoryFree(wb); } void cliSendBatch(SCliConn* pConn) { @@ -1422,41 +1498,30 @@ static void cliSendBatchCb(uv_write_t* req, int status) { cliDestroyBatch(p); taosMemoryFree(req); } -static void cliHandleFastFail(SCliConn* pConn, int status) { + +static void cliHandleFastFail_resp(SCliConn* pConn, int status) { SCliThrd* pThrd = pConn->hostThrd; STrans* pTransInst = pThrd->pTransInst; + SCliMsg* pMsg = transQueueGet(&pConn->cliMsgs, 0); + STraceId* trace = &pMsg->msg.info.traceId; + tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), + TMSG_INFO(pMsg->msg.msgType), pConn, pConn->dstAddr, uv_strerror(status)); +} + +static void cliHandleFastFail_noresp(SCliConn* pConn, int status) { + tError("%s batch msg failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), pConn, + pConn->dstAddr, uv_strerror(status)); + cliDestroyBatch(pConn->pBatch); + pConn->pBatch = NULL; +} +static void cliHandleFastFail(SCliConn* pConn, int status) { if (status == -1) status = UV_EADDRNOTAVAIL; if (pConn->pBatch == NULL) { - SCliMsg* pMsg = transQueueGet(&pConn->cliMsgs, 0); - - STraceId* trace = &pMsg->msg.info.traceId; - tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), - TMSG_INFO(pMsg->msg.msgType), pConn, pConn->dstAddr, uv_strerror(status)); - - if (pMsg != NULL && REQUEST_NO_RESP(&pMsg->msg) && - (pTransInst->failFastFp != NULL && pTransInst->failFastFp(pMsg->msg.msgType))) { - SFailFastItem* item = taosHashGet(pThrd->failFastCache, pConn->dstAddr, strlen(pConn->dstAddr)); - int64_t cTimestamp = taosGetTimestampMs(); - if (item != NULL) { - int32_t elapse = cTimestamp - item->timestamp; - if (elapse >= 0 && elapse <= pTransInst->failFastInterval) { - item->count++; - } else { - item->count = 1; - item->timestamp = cTimestamp; - } - } else { - SFailFastItem item = {.count = 1, .timestamp = cTimestamp}; - taosHashPut(pThrd->failFastCache, pConn->dstAddr, strlen(pConn->dstAddr), &item, sizeof(SFailFastItem)); - } - } + cliHandleFastFail_resp(pConn, status); } else { - tError("%s batch msg failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), - pConn, pConn->dstAddr, uv_strerror(status)); - cliDestroyBatch(pConn->pBatch); - pConn->pBatch = NULL; + cliHandleFastFail_noresp(pConn, status); } cliHandleExcept(pConn); } @@ -1616,9 +1681,8 @@ FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr) { FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx) { if (code != 0) return false; - // if (pCtx->retryCnt == 0) return false; - if (transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet)) return false; - return true; + + return transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet) ? false : true; } FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) { if (pMsg == NULL) return -1; @@ -1686,11 +1750,12 @@ static void doFreeTimeoutMsg(void* param) { SCliMsg* pMsg = arg->param1; SCliThrd* pThrd = arg->param2; STrans* pTransInst = pThrd->pTransInst; - int32_t code = TSDB_CODE_RPC_MAX_SESSIONS; + QUEUE_REMOVE(&pMsg->q); STraceId* trace = &pMsg->msg.info.traceId; tGTrace("%s msg %s cannot get available conn after timeout", pTransInst->label, TMSG_INFO(pMsg->msg.msgType)); - doNotifyApp(pMsg, pThrd, code); + doNotifyApp(pMsg, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); + taosMemoryFree(arg); } @@ -1718,6 +1783,19 @@ static void addConnToHeapCache(SHashObj* pConnHeapCacahe, char* key, SCliConn* p } transHeapInsert(p, pConn); } +static void delConnFromHeapCache(SHashObj* pConnHeapCache, char* key, SCliConn* pConn) { + size_t klen = strlen(key); + + SHeap* p = taosHashGet(pConnHeapCache, key, klen); + if (p == NULL) { + tDebug("failed to get heap cache for key:%s, no need to del", key); + return; + } + int ret = transHeapDelete(p, pConn); + if (ret != 0) { + tDebug("failed to delete conn %p from heap cache, no need to del", pConn); + } +} void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { STraceId* trace = &pMsg->msg.info.traceId; @@ -1742,6 +1820,7 @@ void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { } pConn = cliCreateConn(pThrd); + pConn->dstAddr = taosStrdup(addr); addConnToHeapCache(pThrd->connHeapCache, addr, pConn); return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); @@ -1790,15 +1869,13 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { cliSend(conn); } else { conn = cliCreateConn(pThrd); + conn->dstAddr = taosStrdup(addr); - int64_t refId = (int64_t)pMsg->msg.info.handle; - if (refId != 0) specifyConnRef(conn, true, refId); + specifyConnRef(conn, true, (int64_t)pMsg->msg.info.handle); transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); transQueuePush(&conn->cliMsgs, pMsg); - conn->dstAddr = taosStrdup(addr); - uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn); if (ipaddr == 0xffffffff) { cliResetConnTimer(conn); @@ -2234,7 +2311,6 @@ static SCliThrd* createThrdObj(void* trans) { pThrd->destroyAhandleFp = pTransInst->destroyFp; pThrd->fqdn2ipCache = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - pThrd->failFastCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pThrd->batchCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pThrd->connHeapCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); @@ -2267,7 +2343,6 @@ static void destroyThrdObj(SCliThrd* pThrd) { taosMemoryFree(pThrd->prepare); taosMemoryFree(pThrd->loop); taosHashCleanup(pThrd->fqdn2ipCache); - taosHashCleanup(pThrd->failFastCache); void** pIter = taosHashIterate(pThrd->batchCache, NULL); while (pIter != NULL) { diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index fff13e7ebb..edc2d2b899 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -326,10 +326,6 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) { STransCtxVal* sVal = (STransCtxVal*)iter; key = taosHashGetKey(sVal, &klen); - // STransCtxVal* dVal = taosHashGet(dst->args, key, klen); - // if (dVal) { - // dst->freeFunc(dVal->val); - // } taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal)); iter = taosHashIterate(src->args, iter); } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index d47968eeb8..42189de5d4 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -336,6 +336,59 @@ void uvWhiteListSetConnVer(SIpWhiteListTab* pWhite, SSvrConn* pConn) { pConn->whiteListVer = pWhite->ver; } +static void uvPerfLog(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* pTransMsg) { + STrans* pTransInst = pConn->pTransInst; + 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); + if (cost >= EXCEPTION_LIMIT_US) { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception", + transLabel(pTransInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + (int)cost); + } else { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus", transLabel(pTransInst), pConn, + TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost); + } + } else { + if (cost >= EXCEPTION_LIMIT_US) { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception", + transLabel(pTransInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + pHead->noResp, pTransMsg->code, (int)(cost)); + } else { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus", + transLabel(pTransInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + pHead->noResp, pTransMsg->code, (int)(cost)); + } + } + tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), pTransMsg->info.handle, + pConn, pConn->refId); +} + +static int8_t uvValidConn(SSvrConn* pConn) { + STrans* pTransInst = pConn->pTransInst; + SWorkThrd* pThrd = pConn->hostThrd; + int8_t forbiddenIp = 0; + if (pThrd->enableIpWhiteList) { + forbiddenIp = !uvWhiteListCheckConn(pThrd->pWhiteList, pConn) ? 1 : 0; + if (forbiddenIp == 0) { + uvWhiteListSetConnVer(pThrd->pWhiteList, pConn); + } + } + return forbiddenIp; +} +static void uvMaySetConnAcquired(SSvrConn* pConn, STransMsgHead* pHead) { + if (pConn->status == ConnNormal) { + if (pHead->persist == 1) { + pConn->status = ConnAcquire; + transRefSrvHandle(pConn); + tDebug("conn %p acquired by server app", pConn); + } + } +} static bool uvHandleReq(SSvrConn* pConn) { STrans* pTransInst = pConn->pTransInst; SWorkThrd* pThrd = pConn->hostThrd; @@ -358,14 +411,6 @@ static bool uvHandleReq(SSvrConn* pConn) { pConn->inType = pHead->msgType; memcpy(pConn->user, pHead->user, strlen(pHead->user)); - int8_t forbiddenIp = 0; - if (pThrd->enableIpWhiteList) { - forbiddenIp = !uvWhiteListCheckConn(pThrd->pWhiteList, pConn) ? 1 : 0; - if (forbiddenIp == 0) { - uvWhiteListSetConnVer(pThrd->pWhiteList, pConn); - } - } - if (uvRecvReleaseReq(pConn, pHead)) { return true; } @@ -384,38 +429,7 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; - if (pConn->status == ConnNormal) { - if (pHead->persist == 1) { - pConn->status = ConnAcquire; - transRefSrvHandle(pConn); - tDebug("conn %p acquired by server app", 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); - if (cost >= EXCEPTION_LIMIT_US) { - tGDebug("%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, (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, (int)cost); - } - } else { - if (cost >= EXCEPTION_LIMIT_US) { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception", - transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, - transMsg.code, (int)(cost)); - } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus", - transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), pConn->dst, pConn->src, msgLen, pHead->noResp, - transMsg.code, (int)(cost)); - } - } + uvMaySetConnAcquired(pConn, pHead); // pHead->noResp = 1, // 1. server application should not send resp on handle @@ -423,21 +437,14 @@ static bool uvHandleReq(SSvrConn* pConn) { // 3. not mixed with persist transMsg.info.ahandle = (void*)pHead->ahandle; transMsg.info.handle = (void*)transAcquireExHandle(transGetRefMgt(), pConn->refId); - transMsg.info.refId = pConn->refId; + ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg"); + + transMsg.info.refId = pHead->noResp == 1 ? -1 : pConn->refId; transMsg.info.traceId = pHead->traceId; transMsg.info.cliVer = htonl(pHead->compatibilityVer); - transMsg.info.forbiddenIp = forbiddenIp; + transMsg.info.forbiddenIp = uvValidConn(pConn); - tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn, - pConn->refId); - ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg"); - if (transMsg.info.handle == NULL) { - return false; - } - - if (pHead->noResp == 1) { - transMsg.info.refId = -1; - } + uvPerfLog(pConn, pHead, &transMsg); // set up conn info SRpcConnInfo* pConnInfo = &(transMsg.info.conn); From 1ae87fe097c16cd3bf2824d33b3f3ce2688bfe3e Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Fri, 14 Jun 2024 13:24:58 +0000 Subject: [PATCH 015/240] refactor transport --- source/libs/transport/src/transCli.c | 4 ++-- source/libs/transport/src/transSvr.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 8ec54167af..d625b30752 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2423,7 +2423,7 @@ static void doCloseIdleConn(void* param) { cliDestroyConn(conn, true); taosMemoryFree(arg); } -static void cliSchedMsgToDebug(SCliMsg* pMsg, char* label) { +static void cliPerfLog_schedMsg(SCliMsg* pMsg, char* label) { if (!(rpcDebugFlag & DEBUG_DEBUG)) { return; } @@ -2439,7 +2439,7 @@ static void cliSchedMsgToDebug(SCliMsg* pMsg, char* label) { static void cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { STrans* pTransInst = pThrd->pTransInst; STransConnCtx* pCtx = pMsg->ctx; - cliSchedMsgToDebug(pMsg, transLabel(pThrd->pTransInst)); + cliPerfLog_schedMsg(pMsg, transLabel(pThrd->pTransInst)); STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); arg->param1 = pMsg; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 42189de5d4..57ea89b82a 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -336,7 +336,11 @@ void uvWhiteListSetConnVer(SIpWhiteListTab* pWhite, SSvrConn* pConn) { pConn->whiteListVer = pWhite->ver; } -static void uvPerfLog(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* pTransMsg) { +static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* pTransMsg) { + if (!(rpcDebugFlag & DEBUG_DEBUG)) { + return; + } + STrans* pTransInst = pConn->pTransInst; STraceId* trace = &pHead->traceId; @@ -344,7 +348,7 @@ static void uvPerfLog(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* pTransMs static int64_t EXCEPTION_LIMIT_US = 100 * 1000; if (pConn->status == ConnNormal && pHead->noResp == 0) { - transRefSrvHandle(pConn); + // transRefSrvHandle(pConn); if (cost >= EXCEPTION_LIMIT_US) { tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception", transLabel(pTransInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, @@ -386,6 +390,8 @@ static void uvMaySetConnAcquired(SSvrConn* pConn, STransMsgHead* pHead) { pConn->status = ConnAcquire; transRefSrvHandle(pConn); tDebug("conn %p acquired by server app", pConn); + } else if (pHead->noResp == 0) { + transRefSrvHandle(pConn); } } } @@ -429,8 +435,6 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; - uvMaySetConnAcquired(pConn, pHead); - // pHead->noResp = 1, // 1. server application should not send resp on handle // 2. once send out data, cli conn released to conn pool immediately @@ -444,7 +448,9 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.info.cliVer = htonl(pHead->compatibilityVer); transMsg.info.forbiddenIp = uvValidConn(pConn); - uvPerfLog(pConn, pHead, &transMsg); + uvMaySetConnAcquired(pConn, pHead); + + uvPerfLog_receive(pConn, pHead, &transMsg); // set up conn info SRpcConnInfo* pConnInfo = &(transMsg.info.conn); From cdaa4fa47e295b50b6a78d1edc953b8dc6357b36 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 3 Jul 2024 00:57:44 +0000 Subject: [PATCH 016/240] refactor transport --- source/libs/transport/src/transCli.c | 115 ++++++++++++++++++++------- source/util/src/theap.c | 46 ++++------- 2 files changed, 102 insertions(+), 59 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d625b30752..adb6223a0f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -247,7 +247,7 @@ typedef struct { } SHeap; int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); -int transHeapCreate(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); +int transHeapInit(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); void transHeapDestroy(SHeap* heap); int transHeapGet(SHeap* heap, SCliConn** p); int transHeapInsert(SHeap* heap, SCliConn* p); @@ -1702,12 +1702,11 @@ static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn) uint32_t* v = taosHashGet(cache, fqdn, len); if (v == NULL) { addr = taosGetIpv4FromFqdn(fqdn); - if (addr == 0xffffffff) { + if (addr == (uint32_t)-1) { terrno = TSDB_CODE_RPC_FQDN_ERROR; tError("failed to get ip from fqdn:%s since %s", fqdn, terrstr()); return addr; } - taosHashPut(cache, fqdn, len, &addr, sizeof(addr)); } else { addr = *v; @@ -1717,7 +1716,7 @@ static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn) static FORCE_INLINE void cliUpdateFqdnCache(SHashObj* cache, char* fqdn) { // impl later uint32_t addr = taosGetIpv4FromFqdn(fqdn); - if (addr != 0xffffffff) { + if (addr != (uint32_t)-1) { size_t len = strlen(fqdn); uint32_t* v = taosHashGet(cache, fqdn, len); if (addr != *v) { @@ -1725,7 +1724,7 @@ 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) + 1, &addr, sizeof(addr)); + taosHashPut(cache, fqdn, strlen(fqdn), &addr, sizeof(addr)); } } return; @@ -1759,29 +1758,50 @@ static void doFreeTimeoutMsg(void* param) { taosMemoryFree(arg); } -static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { +static SHeap* getOrCreateHeapIfNotExist(SHashObj* pConnHeapCache, char* key) { + int ret = 0; size_t klen = strlen(key); + SHeap* p = taosHashGet(pConnHeapCache, key, klen); if (p == NULL) { SHeap heap = {0}; - transHeapCreate(&heap, compareHeapNode); - taosHashPut(pConnHeapCache, key, klen, &heap, sizeof(heap)); + ret = transHeapInit(&heap, compareHeapNode); + if (ret != 0) { + tError("failed to init heap cache for key:%s, reason: %s", key, tstrerror(terrno)); + terrno = 0; + return NULL; + } + + ret = taosHashPut(pConnHeapCache, key, klen, &heap, sizeof(heap)); + if (ret != 0) { + transHeapDestroy(&heap); + terrno = TSDB_CODE_OUT_OF_MEMORY; + tError("failed to put heap to cache for key:%s, reason: %s", key, tstrerror(terrno)); + terrno = 0; + } + p = taosHashGet(pConnHeapCache, key, klen); + return p; + } + return p; +} + +static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { + int ret = 0; + SCliConn* pConn = NULL; + SHeap* p = getOrCreateHeapIfNotExist(pConnHeapCache, key); + if (p == NULL) { return NULL; } - SCliConn* pConn = NULL; - transHeapGet(p, &pConn); + ret = transHeapGet(p, &pConn); + return pConn; } -static void addConnToHeapCache(SHashObj* pConnHeapCacahe, char* key, SCliConn* pConn) { - size_t klen = strlen(key); - SHeap* p = taosHashGet(pConnHeapCacahe, key, klen); +static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, char* key, SCliConn* pConn) { + SHeap* p = getOrCreateHeapIfNotExist(pConnHeapCacahe, key); if (p == NULL) { - SHeap heap = {0}; - transHeapCreate(&heap, compareHeapNode); - taosHashPut(pConnHeapCacahe, key, klen, &heap, sizeof(heap)); - p = taosHashGet(pConnHeapCacahe, key, klen); + return 0; } - transHeapInsert(p, pConn); + return transHeapInsert(p, pConn); } static void delConnFromHeapCache(SHashObj* pConnHeapCache, char* key, SCliConn* pConn) { size_t klen = strlen(key); @@ -1797,9 +1817,10 @@ static void delConnFromHeapCache(SHashObj* pConnHeapCache, char* key, SCliConn* } } void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { - STraceId* trace = &pMsg->msg.info.traceId; + int32_t code = 0; - STrans* pTransInst = pThrd->pTransInst; + STraceId* trace = &pMsg->msg.info.traceId; + STrans* pTransInst = pThrd->pTransInst; cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); if (!EPSET_IS_VALID(&pMsg->ctx->epSet)) { @@ -1821,7 +1842,12 @@ void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { pConn = cliCreateConn(pThrd); pConn->dstAddr = taosStrdup(addr); - addConnToHeapCache(pThrd->connHeapCache, addr, pConn); + code = addConnToHeapCache(pThrd->connHeapCache, addr, pConn); + if (code != 0) { + // do nothing + } else { + // do nothing + } return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); } @@ -2858,7 +2884,7 @@ int transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STran 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)); - if (pTransInst == NULL) { + if (pTransInst == NULL || pTransRsp == NULL) { transFreeMsg(pReq->pCont); taosMemoryFree(pTransRsp); return TSDB_CODE_RPC_BROKEN_LINK; @@ -2873,6 +2899,10 @@ int transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMs } tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t)); + if (sem == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tsem_init(sem, 0, 0); TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); @@ -2915,9 +2945,25 @@ _RETURN: } int64_t transCreateSyncMsg(STransMsg* pTransMsg) { tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t)); - tsem_init(sem, 0, 0); + if (sem == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + int ret = tsem_init(sem, 0, 0); + if (ret != 0) { + taosMemoryFree(sem); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } STransSyncMsg* pSyncMsg = taosMemoryCalloc(1, sizeof(STransSyncMsg)); + if (pSyncMsg == NULL) { + tsem_destroy(sem); + taosMemoryFree(sem); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } taosInitRWLatch(&pSyncMsg->latch); pSyncMsg->inited = 0; @@ -2929,13 +2975,16 @@ int64_t transCreateSyncMsg(STransMsg* pTransMsg) { } 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)); + 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) { + transFreeMsg(pReq->pCont); + return TSDB_CODE_OUT_OF_MEMORY; + } SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle); if (pThrd == NULL) { @@ -2953,6 +3002,13 @@ int transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STr pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; pCtx->syncMsgRef = transCreateSyncMsg(pTransMsg); + if (pCtx->syncMsgRef < 0) { + transFreeMsg(pReq->pCont); + taosMemoryFree(pTransMsg); + taosMemoryFree(pCtx); + transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + return terrno; + } int64_t ref = pCtx->syncMsgRef; STransSyncMsg* pSyncMsg = taosAcquireRef(transGetSyncMsgMgt(), ref); @@ -3048,8 +3104,12 @@ int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { } return 1; } -int transHeapCreate(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)) { +int transHeapInit(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)) { heap->heap = heapCreate(cmpFunc); + if (heap->heap == NULL) { + return -1; + } + heap->cmpFunc = cmpFunc; return 0; } @@ -3063,7 +3123,6 @@ int transHeapGet(SHeap* heap, SCliConn** p) { *p = NULL; return -1; } - // HeapNode* minNode = headMin(heap->heap); HeapNode* minNode = heapMin(heap->heap); if (minNode == NULL) { *p = NULL; diff --git a/source/util/src/theap.c b/source/util/src/theap.c index 315ddf9367..ed117efd62 100644 --- a/source/util/src/theap.c +++ b/source/util/src/theap.c @@ -21,6 +21,7 @@ size_t heapSize(Heap* heap) { return heap->nelts; } Heap* heapCreate(HeapCompareFn fn) { Heap* heap = taosMemoryCalloc(1, sizeof(Heap)); if (heap == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -188,7 +189,6 @@ void heapRemove(Heap* heap, HeapNode* node) { void heapDequeue(Heap* heap) { heapRemove(heap, heap->min); } - struct PriorityQueue { SArray* container; pq_comp_fn fn; @@ -204,9 +204,7 @@ PriorityQueue* createPriorityQueue(pq_comp_fn fn, FDelete deleteFn, void* param) return pq; } -void taosPQSetFn(PriorityQueue* pq, pq_comp_fn fn) { - pq->fn = fn; -} +void taosPQSetFn(PriorityQueue* pq, pq_comp_fn fn) { pq->fn = fn; } void destroyPriorityQueue(PriorityQueue* pq) { if (pq->deleteFn) @@ -218,15 +216,15 @@ void destroyPriorityQueue(PriorityQueue* pq) { static size_t pqParent(size_t i) { return (--i) >> 1; /* (i - 1) / 2 */ } static size_t pqLeft(size_t i) { return (i << 1) | 1; /* i * 2 + 1 */ } -static size_t pqRight(size_t i) { return (++i) << 1; /* (i + 1) * 2 */} -static void pqSwapPQNode(PriorityQueueNode* a, PriorityQueueNode* b) { - void * tmp = a->data; - a->data = b->data; - b->data = tmp; +static size_t pqRight(size_t i) { return (++i) << 1; /* (i + 1) * 2 */ } +static void pqSwapPQNode(PriorityQueueNode* a, PriorityQueueNode* b) { + void* tmp = a->data; + a->data = b->data; + b->data = tmp; } #define pqContainerGetEle(pq, i) ((PriorityQueueNode*)taosArrayGet((pq)->container, (i))) -#define pqContainerSize(pq) (taosArrayGetSize((pq)->container)) +#define pqContainerSize(pq) (taosArrayGetSize((pq)->container)) size_t taosPQSize(PriorityQueue* pq) { return pqContainerSize(pq); } @@ -288,9 +286,7 @@ static void pqRemove(PriorityQueue* pq, size_t i) { pqUpdate(pq, i); } -PriorityQueueNode* taosPQTop(PriorityQueue* pq) { - return pqContainerGetEle(pq, 0); -} +PriorityQueueNode* taosPQTop(PriorityQueue* pq) { return pqContainerGetEle(pq, 0); } PriorityQueueNode* taosPQPush(PriorityQueue* pq, const PriorityQueueNode* node) { taosArrayPush(pq->container, node); @@ -316,9 +312,7 @@ BoundedQueue* createBoundedQueue(uint32_t maxSize, pq_comp_fn fn, FDelete delete return q; } -void taosBQSetFn(BoundedQueue* q, pq_comp_fn fn) { - taosPQSetFn(q->queue, fn); -} +void taosBQSetFn(BoundedQueue* q, pq_comp_fn fn) { taosPQSetFn(q->queue, fn); } void destroyBoundedQueue(BoundedQueue* q) { if (!q) return; @@ -343,22 +337,12 @@ PriorityQueueNode* taosBQPush(BoundedQueue* q, PriorityQueueNode* n) { } } -PriorityQueueNode* taosBQTop(BoundedQueue* q) { - return taosPQTop(q->queue); -} +PriorityQueueNode* taosBQTop(BoundedQueue* q) { return taosPQTop(q->queue); } -void taosBQBuildHeap(BoundedQueue *q) { - pqBuildHeap(q->queue); -} +void taosBQBuildHeap(BoundedQueue* q) { pqBuildHeap(q->queue); } -size_t taosBQMaxSize(BoundedQueue* q) { - return q->maxSize; -} +size_t taosBQMaxSize(BoundedQueue* q) { return q->maxSize; } -size_t taosBQSize(BoundedQueue* q) { - return taosPQSize(q->queue); -} +size_t taosBQSize(BoundedQueue* q) { return taosPQSize(q->queue); } -void taosBQPop(BoundedQueue* q) { - taosPQPop(q->queue); -} +void taosBQPop(BoundedQueue* q) { taosPQPop(q->queue); } From 93d391beb1edcf4032c8ec75d3aea80efd8e5441 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 3 Jul 2024 02:53:54 +0000 Subject: [PATCH 017/240] refactor transport --- source/libs/transport/src/transCli.c | 124 +++++++++++++-------------- source/libs/transport/src/transSvr.c | 18 +--- 2 files changed, 62 insertions(+), 80 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index adb6223a0f..aa04bc336f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -398,41 +398,13 @@ void cliResetConnTimer(SCliConn* conn) { tDebug("%s conn %p stop timer", CONN_GET_INST_LABEL(conn), conn); uv_timer_stop(conn->timer); } + taosArrayPush(pThrd->timerList, &conn->timer); conn->timer->data = NULL; conn->timer = NULL; } } -void cliHandleBatchResp(SCliConn* conn) { - ASSERT(0); - SCliThrd* pThrd = conn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; - cliResetConnTimer(conn); - - STransMsgHead* pHead = NULL; - int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead); - if (transDecompressMsg((char**)&pHead, msgLen) < 0) { - tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); - } - pHead->code = htonl(pHead->code); - pHead->msgLen = htonl(pHead->msgLen); - - STransMsg transMsg = {0}; - transMsg.contLen = transContLenFromMsg(pHead->msgLen); - transMsg.pCont = transContFromHead((char*)pHead); - transMsg.code = pHead->code; - transMsg.msgType = pHead->msgType; - transMsg.info.ahandle = NULL; - transMsg.info.traceId = pHead->traceId; - transMsg.info.hasEpSet = pHead->hasEpSet; - transMsg.info.cliVer = htonl(pHead->compatibilityVer); - - SCliMsg* pMsg = NULL; - STransConnCtx* pCtx = pMsg->ctx; - if (cliAppCb(conn, &transMsg, pMsg) != 0) { - return; - } -} +void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } SCliMsg* cliFindMsgBySeqnum(SCliConn* conn, int32_t seqNum) { SCliMsg* pMsg = NULL; @@ -487,8 +459,6 @@ void cliHandleResp_shareConn(SCliConn* conn) { if (cliAppCb(conn, &transMsg, pMsg) != 0) { return; } - - return; } void cliHandleResp(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; @@ -1387,7 +1357,7 @@ static void cliDestroyBatch(SCliBatch* pBatch) { static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { STrans* pTransInst = pThrd->pTransInst; uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, ip); - if (ipaddr == 0xffffffff) { + if (ipaddr == (uint32_t)(-1)) { cliResetConnTimer(conn); cliHandleFastFail(conn, -1); return; @@ -1399,6 +1369,7 @@ static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { addr.sin_port = (uint16_t)htons(port); tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, conn->dstAddr); + int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); if (fd == -1) { tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, @@ -1406,6 +1377,7 @@ static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { cliHandleFastFail(conn, -1); return; } + int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); if (ret != 0) { tError("%s conn %p failed to set stream, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); @@ -1426,7 +1398,15 @@ static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { cliHandleFastFail(conn, -1); return; } - uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + + ret = uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + if (ret != 0) { + tError("%s conn %p failed to start timer, reason:%s", transLabel(pTransInst), conn, uv_err_name(ret)); + cliResetConnTimer(conn); + cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); + cliHandleFastFail(conn, -1); + return; + } return; } static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { @@ -1462,16 +1442,15 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { cliSendBatch(conn); } static void cliSendBatchCb(uv_write_t* req, int status) { - SCliConn* conn = req->data; - SCliThrd* thrd = conn->hostThrd; + SCliConn* conn = req->data; + SCliThrd* thrd = conn->hostThrd; + SCliBatch* p = conn->pBatch; - - SCliBatchList* pBatchList = p->pList; - SCliBatch* nxtBatch = cliGetHeadFromList(pBatchList); - pBatchList->connCnt -= 1; - conn->pBatch = NULL; + SCliBatch* nxtBatch = cliGetHeadFromList(p->pList); + p->pList->connCnt -= 1; + if (status != 0) { tDebug("%s conn %p failed to send batch msg, batch size:%d, msgLen:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, p->wLen, p->batchSize, uv_err_name(status)); @@ -1491,7 +1470,6 @@ static void cliSendBatchCb(uv_write_t* req, int status) { } } else { cliDestroyBatch(nxtBatch); - // conn release by other callback } } @@ -2649,23 +2627,7 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { cliSchedMsgToNextNode(pMsg, pThrd); return true; } -int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pTransInst = pThrd->pTransInst; - - if (pMsg == NULL || pMsg->ctx == NULL) { - tTrace("%s conn %p handle resp", pTransInst->label, pConn); - pTransInst->cfp(pTransInst->parent, pResp, NULL); - return 0; - } - - STransConnCtx* pCtx = pMsg->ctx; - - bool retry = cliGenRetryRule(pConn, pResp, pMsg); - if (retry == true) { - return -1; - } - +void cliMayReSetRespCode(STransConnCtx* pCtx, STransMsg* pResp) { if (pCtx->retryCode != TSDB_CODE_SUCCESS) { int32_t code = pResp->code; // return internal code app @@ -2683,6 +2645,24 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { pResp->code = TSDB_CODE_RPC_SOMENODE_BROKEN_LINK; } } +} +int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pTransInst = pThrd->pTransInst; + + if (pMsg == NULL || pMsg->ctx == NULL) { + tTrace("%s conn %p handle resp", pTransInst->label, pConn); + pTransInst->cfp(pTransInst->parent, pResp, NULL); + return 0; + } + + bool retry = cliGenRetryRule(pConn, pResp, pMsg); + if (retry == true) { + return -1; + } + + STransConnCtx* pCtx = pMsg->ctx; + cliMayReSetRespCode(pCtx, pResp); STraceId* trace = &pResp->info.traceId; bool hasEpSet = cliTryExtractEpSet(pResp, &pCtx->epSet); @@ -2817,7 +2797,13 @@ int transReleaseCliHandle(void* handle) { } static SCliMsg* transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) { TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); + STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + if (pCtx == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + epsetAssign(&pCtx->epSet, pEpSet); epsetAssign(&pCtx->origEpSet, pEpSet); @@ -2827,6 +2813,12 @@ 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); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + cliMsg->ctx = pCtx; cliMsg->msg = *pReq; cliMsg->st = taosGetTimestampUs(); @@ -3059,12 +3051,16 @@ int transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { return TSDB_CODE_RPC_BROKEN_LINK; } - SCvtAddr cvtAddr = {0}; - if (ip != NULL && fqdn != NULL) { - tstrncpy(cvtAddr.ip, ip, sizeof(cvtAddr.ip)); - tstrncpy(cvtAddr.fqdn, fqdn, sizeof(cvtAddr.fqdn)); - cvtAddr.cvt = true; + if (ip == NULL || fqdn == NULL) { + transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + return TSDB_CODE_RPC_FQDN_ERROR; } + + SCvtAddr cvtAddr = {0}; + tstrncpy(cvtAddr.ip, ip, sizeof(cvtAddr.ip)); + tstrncpy(cvtAddr.fqdn, fqdn, sizeof(cvtAddr.fqdn)); + cvtAddr.cvt = true; + for (int i = 0; i < pTransInst->numOfThreads; i++) { STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); pCtx->cvtAddr = cvtAddr; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 57ea89b82a..907f132d32 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -421,15 +421,7 @@ static bool uvHandleReq(SSvrConn* pConn) { return true; } - // TODO(dengyihao): time-consuming task throwed into BG Thread - // uv_work_t* wreq = taosMemoryMalloc(sizeof(uv_work_t)); - // wreq->data = pConn; - // uv_read_stop((uv_stream_t*)pConn->pTcp); - // transRefSrvHandle(pConn); - // uv_queue_work(((SWorkThrd*)pConn->hostThrd)->loop, wreq, uvWorkDoTask, uvWorkAfterTask); - - STransMsg transMsg; - memset(&transMsg, 0, sizeof(transMsg)); + STransMsg transMsg = {0}; transMsg.contLen = transContLenFromMsg(pHead->msgLen); transMsg.pCont = pHead->content; transMsg.msgType = pHead->msgType; @@ -942,14 +934,9 @@ 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); pConn->pTransInst = pThrd->pTransInst; - /* init conn timer*/ - // uv_timer_init(pThrd->loop, &pConn->pTimer); - // pConn->pTimer.data = pConn; pConn->hostThrd = pThrd; @@ -1107,6 +1094,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { 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); @@ -1618,5 +1606,3 @@ void transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { } transReleaseExHandle(transGetInstMgt(), (int64_t)thandle); } - -int transGetConnInfo(void* thandle, STransHandleInfo* pConnInfo) { return -1; } From 620f4c58067749854c1892797b6cac60650ac6e6 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 3 Jul 2024 06:46:38 +0000 Subject: [PATCH 018/240] refactor transport --- source/libs/transport/src/transCli.c | 81 ++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index aa04bc336f..dfeea77035 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -85,6 +85,7 @@ typedef struct SCliConn { int64_t refId; int32_t seq; + int32_t shareCnt; } SCliConn; typedef struct SCliMsg { @@ -230,6 +231,10 @@ static FORCE_INLINE void destroyCmsgAndAhandle(void* cmsg); static FORCE_INLINE int cliRBChoseIdx(STrans* pTransInst); static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx); +static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); +static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); +static void delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); + // thread obj static SCliThrd* createThrdObj(void* trans); static void destroyThrdObj(SCliThrd* pThrd); @@ -420,6 +425,15 @@ SCliMsg* cliFindMsgBySeqnum(SCliConn* conn, int32_t seqNum) { } return pMsg; } +bool cliShouldAddConnToPool(SCliConn* conn) { + SCliThrd* pThrd = conn->hostThrd; + bool empty = transQueueEmpty(&conn->cliMsgs); + if (empty) { + delConnFromHeapCache(pThrd->connHeapCache, conn); + } + + return empty; +} void cliHandleResp_shareConn(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pTransInst = pThrd->pTransInst; @@ -1113,12 +1127,42 @@ static void cliSendCb(uv_write_t* req, int status) { uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); } +static void cliHandleBatch_shareConnExcept(SCliConn* conn) { + int32_t code = -1; + SCliThrd* pThrd = conn->hostThrd; + STrans* pTransInst = pThrd->pTransInst; + for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) { + SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, i); + ASSERT(pMsg->type != Release); + ASSERT(REQUEST_NO_RESP(&pMsg->msg) == 0); + + STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL; + STransMsg transMsg = {0}; + transMsg.code = code == -1 ? (conn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; + transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0; + transMsg.info.ahandle = NULL; + transMsg.info.cliVer = pTransInst->compatibilityVer; + transMsg.info.ahandle = pCtx->ahandle; + + int32_t ret = cliAppCb(conn, &transMsg, pMsg); + } + + // SCliConn* conn = req->data; + // if (status != 0) { + // tDebug("%s conn %p failed to send batch msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); + // return; + // } + + // uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + // taosMemoryFree(req); +} static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { SCliConn* conn = req->data; + conn->shareCnt -= 1; if (status != 0) { tDebug("%s conn %p failed to send batch msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); if (!uv_is_closing((uv_handle_t*)&conn->stream)) { - cliHandleExcept(conn); + cliHandleBatch_shareConnExcept(conn); } return; } @@ -1189,6 +1233,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { } uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); req->data = pConn; + pConn->shareCnt += 1; tDebug("%s conn %p start to send batch msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliSendBatch_shareConnCb); @@ -1359,7 +1404,12 @@ static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, ip); if (ipaddr == (uint32_t)(-1)) { cliResetConnTimer(conn); - cliHandleFastFail(conn, -1); + if (conn->pBatch != NULL) { + cliHandleFastFail(conn, -1); + } else { + cliHandleBatch_shareConnExcept(conn); + } + return; } @@ -1774,19 +1824,17 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return pConn; } -static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, char* key, SCliConn* pConn) { - SHeap* p = getOrCreateHeapIfNotExist(pConnHeapCacahe, key); +static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { + SHeap* p = getOrCreateHeapIfNotExist(pConnHeapCacahe, pConn->dstAddr); if (p == NULL) { return 0; } return transHeapInsert(p, pConn); } -static void delConnFromHeapCache(SHashObj* pConnHeapCache, char* key, SCliConn* pConn) { - size_t klen = strlen(key); - - SHeap* p = taosHashGet(pConnHeapCache, key, klen); +static void delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { + SHeap* p = taosHashGet(pConnHeapCache, pConn->dstAddr, strlen(pConn->dstAddr)); if (p == NULL) { - tDebug("failed to get heap cache for key:%s, no need to del", key); + tDebug("failed to get heap cache for key:%s, no need to del", pConn->dstAddr); return; } int ret = transHeapDelete(p, pConn); @@ -1814,19 +1862,22 @@ void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { bool ignore = false; pConn = getConnFromPool(pThrd, addr, &ignore); if (pConn != NULL) { + addConnToHeapCache(pThrd->connHeapCache, pConn); + transQueuePush(&pConn->cliMsgs, pMsg); return cliSendBatch_shareConn(pConn); } + } else { + tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); + transQueuePush(&pConn->cliMsgs, pMsg); + cliSendBatch_shareConn(pConn); + return; } pConn = cliCreateConn(pThrd); pConn->dstAddr = taosStrdup(addr); - code = addConnToHeapCache(pThrd->connHeapCache, addr, pConn); - if (code != 0) { - // do nothing - } else { - // do nothing - } + code = addConnToHeapCache(pThrd->connHeapCache, pConn); + transQueuePush(&pConn->cliMsgs, pMsg); return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); } void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { From 4e3a7855745d83b5edccee7be29abb3f3c442249 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 3 Jul 2024 08:01:48 +0000 Subject: [PATCH 019/240] refactor transport --- source/libs/transport/src/transCli.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index dfeea77035..4ece709289 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1145,6 +1145,9 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { transMsg.info.ahandle = pCtx->ahandle; int32_t ret = cliAppCb(conn, &transMsg, pMsg); + if (ret != 0) { + return; + } } // SCliConn* conn = req->data; From 0a138a5078ee0ff6e6c42bdf8c9dade808d83ca7 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 11 Jul 2024 10:14:46 +0000 Subject: [PATCH 020/240] refactor code --- source/libs/transport/src/transCli.c | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4ece709289..1afca14e5e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -470,8 +470,11 @@ void cliHandleResp_shareConn(SCliConn* conn) { transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; STraceId* trace = &transMsg.info.traceId; - if (cliAppCb(conn, &transMsg, pMsg) != 0) { + int32_t ret = cliAppCb(conn, &transMsg, pMsg); + if (ret != 0) { return; + } else { + destroyCmsg(pMsg); } } void cliHandleResp(SCliConn* conn) { @@ -1131,33 +1134,32 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { int32_t code = -1; SCliThrd* pThrd = conn->hostThrd; STrans* pTransInst = pThrd->pTransInst; - for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) { - SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, i); + while (!transQueueEmpty(&conn->cliMsgs)) { + SCliMsg* pMsg = transQueuePop(&conn->cliMsgs); ASSERT(pMsg->type != Release); ASSERT(REQUEST_NO_RESP(&pMsg->msg) == 0); STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL; - STransMsg transMsg = {0}; + + STransMsg transMsg = {0}; transMsg.code = code == -1 ? (conn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0; transMsg.info.ahandle = NULL; transMsg.info.cliVer = pTransInst->compatibilityVer; transMsg.info.ahandle = pCtx->ahandle; - int32_t ret = cliAppCb(conn, &transMsg, pMsg); - if (ret != 0) { - return; + pMsg->seqNum = 0; + code = cliAppCb(conn, &transMsg, pMsg); + if (code != 0) { + continue; + } else { + // already notify user + destroyCmsg(pMsg); } } - // SCliConn* conn = req->data; - // if (status != 0) { - // tDebug("%s conn %p failed to send batch msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); - // return; - // } - - // uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); - // taosMemoryFree(req); + if (T_REF_VAL_GET(conn) > 1) transUnrefCliHandle(conn); + transUnrefCliHandle(conn); } static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { SCliConn* conn = req->data; From 6e004abc7d4985194368b173702f3a73db011d0c Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Fri, 12 Jul 2024 11:35:14 +0000 Subject: [PATCH 021/240] opt transport --- source/libs/transport/src/transCli.c | 3 ++- source/libs/transport/src/transSvr.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1afca14e5e..82c0b9fd44 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1182,7 +1182,8 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int32_t totalLen = 0; if (size == 0) { tError("%s conn %p not msg to send", pTransInst->label, pConn); - cliHandleExcept(pConn); + ASSERT(0); + // cliHandleExcept(pConn); return; } uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 907f132d32..c74a841a61 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -427,6 +427,9 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; + if (pHead->seqNum != 0) { + ASSERT(0); + } // pHead->noResp = 1, // 1. server application should not send resp on handle // 2. once send out data, cli conn released to conn pool immediately From 58569208d563d09ae77d22683528d57d69f94920 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 20 Aug 2024 11:47:07 +0800 Subject: [PATCH 022/240] refactor transport --- source/libs/transport/src/transCli.c | 258 +++++++++++++------------- source/libs/transport/src/transComm.c | 1 + 2 files changed, 133 insertions(+), 126 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b98421cb76..701cd55d9b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -173,8 +173,8 @@ static void cliSendCb(uv_write_t* req, int status); // callback after conn to server static void cliConnCb(uv_connect_t* req, int status); static void cliAsyncCb(uv_async_t* handle); -static void cliIdleCb(uv_idle_t* handle); -static void cliPrepareCb(uv_prepare_t* handle); +// static void cliIdleCb(uv_idle_t* handle); +// static void cliPrepareCb(uv_prepare_t* handle); static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd); static void cliSendBatchCb(uv_write_t* req, int status); @@ -185,7 +185,7 @@ static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); static int32_t allocConnRef(SCliConn* conn, bool update); -static int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg); +static int cliNotifyCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg); void cliResetConnTimer(SCliConn* conn); static int32_t cliCreateConn(SCliThrd* thrd, SCliConn** pCliConn); @@ -200,10 +200,11 @@ static int32_t cliPreCheckSessionLimitForMsg(SCliThrd* pThrd, char* addr, SCliMs static void cliDestroyBatch(SCliBatch* pBatch); // cli util func -static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx); -static FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr); +static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx); +static FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr); static FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* resp); +static FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliMsg* pMsg, int32_t code); static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ipaddr); static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn); @@ -216,7 +217,7 @@ static void cliHandleExcept(SCliConn* conn, int32_t code); static void cliReleaseUnfinishedMsg(SCliConn* conn); static void cliHandleFastFail(SCliConn* pConn, int status); -static void doNotifyApp(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code); +static void doNotifyCb(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code); // handle req from app static void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd); static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd); @@ -240,7 +241,7 @@ static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx); static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); -static void delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); +static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); // thread obj static int32_t createThrdObj(void* trans, SCliThrd** pThrd); @@ -260,11 +261,11 @@ typedef struct { } SHeap; int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); -int transHeapInit(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); +int32_t transHeapInit(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); void transHeapDestroy(SHeap* heap); -int transHeapGet(SHeap* heap, SCliConn** p); -int transHeapInsert(SHeap* heap, SCliConn* p); -int transHeapDelete(SHeap* heap, SCliConn* p); +int32_t transHeapGet(SHeap* heap, SCliConn** p); +int32_t transHeapInsert(SHeap* heap, SCliConn* p); +int32_t transHeapDelete(SHeap* heap, SCliConn* p); #define CLI_RELEASE_UV(loop) \ do { \ @@ -437,7 +438,7 @@ bool cliShouldAddConnToPool(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; bool empty = transQueueEmpty(&conn->cliMsgs); if (empty) { - delConnFromHeapCache(pThrd->connHeapCache, conn); + (void)delConnFromHeapCache(pThrd->connHeapCache, conn); } return empty; @@ -478,7 +479,7 @@ void cliHandleResp_shareConn(SCliConn* conn) { transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; STraceId* trace = &transMsg.info.traceId; - int32_t ret = cliAppCb(conn, &transMsg, pMsg); + int32_t ret = cliNotifyCb(conn, &transMsg, pMsg); if (ret != 0) { return; } else { @@ -577,7 +578,7 @@ void cliHandleResp(SCliConn* conn) { } if (pMsg == NULL || (pMsg && pMsg->type != Release)) { - if (cliAppCb(conn, &transMsg, pMsg) != 0) { + if (cliNotifyCb(conn, &transMsg, pMsg) != 0) { return; } } @@ -675,7 +676,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { if (pMsg == NULL || (pMsg && pMsg->type != Release)) { int64_t refId = (pMsg == NULL ? 0 : (int64_t)(pMsg->msg.info.handle)); cliDestroyMsgInExhandle(refId); - if (cliAppCb(pConn, &transMsg, pMsg) != 0) { + if (cliNotifyCb(pConn, &transMsg, pMsg) != 0) { return; } } @@ -735,7 +736,7 @@ void* destroyConnPool(SCliThrd* pThrd) { transDQCancel(pThrd->waitConnQueue, pMsg->ctx->task); pMsg->ctx->task = NULL; - doNotifyApp(pMsg, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); + doNotifyCb(pMsg, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); } taosMemoryFree(msglist); @@ -817,14 +818,14 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { if (pInst->notWaitAvaliableConn || (pInst->noDelayFp != NULL && pInst->noDelayFp((*pMsg)->msg.msgType))) { tDebug("%s msg %s not to send, reason: %s", pInst->label, TMSG_INFO((*pMsg)->msg.msgType), tstrerror(TSDB_CODE_RPC_NETWORK_BUSY)); - doNotifyApp(*pMsg, pThrd, TSDB_CODE_RPC_NETWORK_BUSY); + doNotifyCb(*pMsg, pThrd, TSDB_CODE_RPC_NETWORK_BUSY); *pMsg = NULL; return NULL; } STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); if (arg == NULL) { - doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + doNotifyCb(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); *pMsg = NULL; return NULL; } @@ -834,7 +835,7 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); if (task == NULL) { taosMemoryFree(arg); - doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + doNotifyCb(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); *pMsg = NULL; return NULL; } @@ -847,7 +848,7 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { if (!(QUEUE_IS_EMPTY(&(list)->msgQ))) { STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); if (arg == NULL) { - doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + doNotifyCb(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); *pMsg = NULL; return NULL; } @@ -857,7 +858,7 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); if (task == NULL) { taosMemoryFree(arg); - doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + doNotifyCb(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); *pMsg = NULL; return NULL; } @@ -1255,7 +1256,7 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { transMsg.info.ahandle = pCtx->ahandle; pMsg->seqNum = 0; - code = cliAppCb(conn, &transMsg, pMsg); + code = cliNotifyCb(conn, &transMsg, pMsg); if (code != 0) { continue; } else { @@ -1752,7 +1753,7 @@ void cliConnCb(uv_connect_t* req, int status) { return cliSend(pConn); } -static void doNotifyApp(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code) { +static void doNotifyCb(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code) { STransConnCtx* pCtx = pMsg->ctx; STrans* pInst = pThrd->pInst; @@ -1891,14 +1892,22 @@ SCliConn* cliGetConn(SCliMsg** pMsg, SCliThrd* pThrd, bool* ignore, char* addr) } return conn; } -FORCE_INLINE void cliMayCvtFqdnToIp(SEpSet* pEpSet, SCvtAddr* pCvtAddr) { +FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr) { if (pCvtAddr->cvt == false) { - return; + if (EPSET_IS_VALID(pEpSet)) { + return 0; + } else { + return TSDB_CODE_RPC_FQDN_ERROR; + } } if (pEpSet->numOfEps == 1 && strncmp(pEpSet->eps[0].fqdn, pCvtAddr->fqdn, TSDB_FQDN_LEN) == 0) { memset(pEpSet->eps[0].fqdn, 0, TSDB_FQDN_LEN); memcpy(pEpSet->eps[0].fqdn, pCvtAddr->ip, TSDB_FQDN_LEN); } + if (EPSET_IS_VALID(pEpSet)) { + return 0; + } + return TSDB_CODE_RPC_FQDN_ERROR; } FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx) { @@ -1906,11 +1915,10 @@ FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx) { return transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet) ? false : true; } + FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) { if (pMsg == NULL) return -1; - // memset(pResp, 0, sizeof(STransMsg)); - if (pResp->code == 0) { pResp->code = TSDB_CODE_RPC_BROKEN_LINK; } @@ -1921,6 +1929,20 @@ FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) { return 0; } +FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliMsg* pMsg, int32_t code) { + STrans* pInst = pThrd->pInst; + + STransMsg resp = {.code = code}; + code = cliBuildExceptResp(pMsg, &resp); + if (code != 0) { + return code; + } + resp.info.cliVer = pInst->compatibilityVer; + pInst->cfp(pInst->parent, &resp, NULL); + + return 0; +} + static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ip) { int32_t code = 0; uint32_t addr = 0; @@ -1987,7 +2009,7 @@ static void doFreeTimeoutMsg(void* param) { STraceId* trace = &pMsg->msg.info.traceId; tGTrace("%s msg %s cannot get available conn after timeout", pInst->label, TMSG_INFO(pMsg->msg.msgType)); - doNotifyApp(pMsg, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); + doNotifyCb(pMsg, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); taosMemoryFree(arg); } @@ -2044,28 +2066,33 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { } return transHeapInsert(p, pConn); } -static void delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { + +static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { SHeap* p = taosHashGet(pConnHeapCache, pConn->dstAddr, strlen(pConn->dstAddr)); if (p == NULL) { tDebug("failed to get heap cache for key:%s, no need to del", pConn->dstAddr); - return; + return 0; } - int32_t code = transHeapDelete(p, pConn); + int32_t code = transHeapDelete(p, pConn); if (code != 0) { tDebug("failed to delete conn %p from heap cache since %s", pConn, tstrerror(code)); } + return code; } + void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { int32_t code = 0; STraceId* trace = &pMsg->msg.info.traceId; STrans* pInst = pThrd->pInst; - cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); - if (!EPSET_IS_VALID(&pMsg->ctx->epSet)) { + code = cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); + if (code != 0) { + // notifyCb destroyCmsg(pMsg); return; } + char addr[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); @@ -2093,18 +2120,14 @@ void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { transQueuePush(&pConn->cliMsgs, pMsg); return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); } -void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { - int32_t code = 0; + +void cliHandleReq__noShareConn(SCliMsg* pMsg, SCliThrd* pThrd) { + int32_t code; STrans* pInst = pThrd->pInst; - - if (pInst->shareConn == 1) { - return cliHandleReq__shareConn(pMsg, pThrd); - } - - cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); - if (!EPSET_IS_VALID(&pMsg->ctx->epSet)) { + code = cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); + if (code != 0) { + // notifyCb destroyCmsg(pMsg); - return; } char* fqdn = EPSET_GET_INUSE_IP(&pMsg->ctx->epSet); @@ -2117,12 +2140,8 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { if (ignore == true) { // persist conn already release by server STransMsg resp = {0}; - (void)cliBuildExceptResp(pMsg, &resp); - // refactorr later - resp.info.cliVer = pInst->compatibilityVer; - if (pMsg->type != Release) { - pInst->cfp(pInst->parent, &resp, NULL); + (void)cliBuildExceptRespAndNotifyCb(pThrd, pMsg, 0); } destroyCmsg(pMsg); return; @@ -2140,13 +2159,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { code = cliCreateConn(pThrd, &conn); if (code != 0) { tError("%s failed to create conn, reason:%s", pInst->label, tstrerror(code)); - STransMsg resp = {.code = code}; - (void)cliBuildExceptResp(pMsg, &resp); - - resp.info.cliVer = pInst->compatibilityVer; - if (pMsg->type != Release) { - pInst->cfp(pInst->parent, &resp, NULL); - } + (void)cliBuildExceptRespAndNotifyCb(pThrd, pMsg, code); destroyCmsg(pMsg); return; } @@ -2207,6 +2220,15 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { tGTrace("%s conn %p ready", pInst->label, conn); } +void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { + STrans* pInst = pThrd->pInst; + if (pInst->shareConn == 1) { + return cliHandleReq__shareConn(pMsg, pThrd); + } else { + return cliHandleReq__noShareConn(pMsg, pThrd); + } +} + static void cliDealReq(queue* wq, SCliThrd* pThrd) { int count = 0; @@ -2243,6 +2265,7 @@ SCliBatch* cliGetHeadFromList(SCliBatchList* pList) { static void cliBuildBatch(SCliMsg* pMsg, queue* h, SCliThrd* pThrd) { STrans* pInst = pThrd->pInst; STransConnCtx* pCtx = pMsg->ctx; + return; } static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, uint32_t port) { SCliBatchList* pBatchList = taosMemoryCalloc(1, sizeof(SCliBatchList)); @@ -2316,11 +2339,6 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - // if (pMsg->type == Normal) { - // cliBuildBatch(pMsg, h, pThrd); - // continue; - // // count++; - // } if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { cliBuildBatch(pMsg, h, pThrd); continue; @@ -2342,6 +2360,7 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { destroyCmsg(pMsg); continue; } + pBatchList->batchLenLimit = pInst->batchSize; SCliBatch* pBatch = NULL; @@ -2416,33 +2435,6 @@ static void cliAsyncCb(uv_async_t* handle) { if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd); } -static void cliPrepareCb(uv_prepare_t* handle) { - SCliThrd* thrd = handle->data; - tTrace("prepare work start"); - - SAsyncPool* pool = thrd->asyncPool; - for (int i = 0; i < pool->nAsync; i++) { - uv_async_t* async = &(pool->asyncs[i]); - SAsyncItem* item = async->data; - - queue wq; - (void)taosThreadMutexLock(&item->mtx); - QUEUE_MOVE(&item->qmsg, &wq); - (void)taosThreadMutexUnlock(&item->mtx); - - int count = 0; - while (!QUEUE_IS_EMPTY(&wq)) { - queue* h = QUEUE_HEAD(&wq); - QUEUE_REMOVE(h); - - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - (*cliAsyncHandle[pMsg->type])(pMsg, thrd); - count++; - } - } - tTrace("prepare work end"); - if (thrd->stopMsg != NULL) cliHandleQuit(thrd->stopMsg, thrd); -} void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { transCtxCleanup(&conn->ctx); @@ -2464,12 +2456,9 @@ void cliConnFreeMsgs(SCliConn* conn) { continue; } - STransMsg resp = {0}; - if (-1 == cliBuildExceptResp(cmsg, &resp)) { + if (cliBuildExceptRespAndNotifyCb(pThrd, cmsg, 0) != 0) { continue; } - resp.info.cliVer = pInst->compatibilityVer; - pInst->cfp(pInst->parent, &resp, NULL); cmsg->ctx->ahandle = NULL; } @@ -2637,19 +2626,6 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(code, NULL, _end); } - pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t)); - 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; - int32_t timerSize = 64; pThrd->timerList = taosArrayInit(timerSize, sizeof(void*)); if (pThrd->timerList == NULL) { @@ -2716,7 +2692,6 @@ _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++) { @@ -2840,7 +2815,7 @@ static FORCE_INLINE void doDelayTask(void* param) { taosMemoryFree(arg); } -static void doCloseIdleConn(void* param) { +static FORCE_INLINE void doCloseIdleConn(void* param) { STaskArg* arg = param; SCliConn* conn = arg->param1; tDebug("%s conn %p idle, close it", CONN_GET_INST_LABEL(conn), conn); @@ -2848,7 +2823,7 @@ static void doCloseIdleConn(void* param) { cliDestroyConn(conn, true); taosMemoryFree(arg); } -static void cliPerfLog_schedMsg(SCliMsg* pMsg, char* label) { +static FORCE_INLINE void cliPerfLog_schedMsg(SCliMsg* pMsg, char* label) { if (!(rpcDebugFlag & DEBUG_DEBUG)) { return; } @@ -2856,21 +2831,30 @@ static void cliPerfLog_schedMsg(SCliMsg* pMsg, char* label) { STraceId* trace = &pMsg->msg.info.traceId; char tbuf[512] = {0}; (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; } -static void cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { +static FORCE_INLINE int32_t cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { STrans* pInst = pThrd->pInst; STransConnCtx* pCtx = pMsg->ctx; cliPerfLog_schedMsg(pMsg, transLabel(pThrd->pInst)); STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + if (arg == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } arg->param1 = pMsg; arg->param2 = pThrd; - (void)transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); + SDelayTask* pTask = transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); + if (pTask == NULL) { + taosMemoryFree(arg); + return TSDB_CODE_OUT_OF_MEMORY; + } + return 0; } FORCE_INLINE bool cliTryExtractEpSet(STransMsg* pResp, SEpSet* dst) { @@ -2963,18 +2947,17 @@ bool cliResetEpset(STransConnCtx* pCtx, STransMsg* pResp, bool hasEpSet) { } return noDelay; } -bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pInst = pThrd->pInst; - STransConnCtx* pCtx = pMsg->ctx; - int32_t code = pResp->code; - - bool retry = pInst->retry != NULL ? pInst->retry(code, pResp->msgType - 1) : false; +int8_t cliRetryShouldRetry(STrans* pInst, STransMsg* pResp) { + bool retry = pInst->retry != NULL ? pInst->retry(pResp->code, pResp->msgType - 1) : false; if (retry == false) { - return false; + return 0; } + return 1; +} +void cliRetryMayInitCtx(STrans* pInst, SCliMsg* pMsg) { + STransConnCtx* pCtx = pMsg->ctx; if (!pCtx->retryInit) { pCtx->retryMinInterval = pInst->retryMinInterval; pCtx->retryMaxInterval = pInst->retryMaxInterval; @@ -2985,15 +2968,32 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { pCtx->retryStep = 0; pCtx->retryInit = true; pCtx->retryCode = TSDB_CODE_SUCCESS; - - // already retry, not use handle specified by app; pMsg->msg.info.handle = 0; } +} +int32_t cliRetryIsTimeout(STrans* pInst, SCliMsg* pMsg) { + STransConnCtx* pCtx = pMsg->ctx; + if (pCtx->retryMaxTimeout != -1 && taosGetTimestampMs() - pCtx->retryInitTimestamp >= pCtx->retryMaxTimeout) { + return 1; + } + return 0; +} +bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; - if (-1 != pCtx->retryMaxTimeout && taosGetTimestampMs() - pCtx->retryInitTimestamp >= pCtx->retryMaxTimeout) { + STransConnCtx* pCtx = pMsg->ctx; + int32_t code = pResp->code; + + cliRetryMayInitCtx(pInst, pMsg); + + if (!cliRetryShouldRetry(pInst, pResp)) { return false; } + if (cliRetryIsTimeout(pInst, pMsg)) { + return false; + } // code, msgType // A: epset,leader, not self @@ -3045,7 +3045,12 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } pMsg->sent = 0; - cliSchedMsgToNextNode(pMsg, pThrd); + code = cliSchedMsgToNextNode(pMsg, pThrd); + if (code != 0) { + pResp->code = code; + tError("failed to sched msg to next node, reason:%s", tstrerror(code)); + return false; + } return true; } void cliMayReSetRespCode(STransConnCtx* pCtx, STransMsg* pResp) { @@ -3067,7 +3072,7 @@ void cliMayReSetRespCode(STransConnCtx* pCtx, STransMsg* pResp) { } } } -int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { +int cliNotifyCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; @@ -3277,7 +3282,7 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S int64_t handle = (int64_t)pReq->info.handle; SCliThrd* pThrd = transGetWorkThrd(pInst, handle); if (pThrd == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _exception;); + TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _exception); } if (handle != 0) { @@ -3702,6 +3707,7 @@ _exception: return code; } +// conn heap int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { SCliConn* args1 = container_of(a, SCliConn, node); SCliConn* args2 = container_of(b, SCliConn, node); @@ -3724,7 +3730,7 @@ void transHeapDestroy(SHeap* heap) { heapDestroy(heap->heap); } } -int transHeapGet(SHeap* heap, SCliConn** p) { +int32_t transHeapGet(SHeap* heap, SCliConn** p) { if (heapSize(heap->heap) == 0) { *p = NULL; return -1; @@ -3737,7 +3743,7 @@ int transHeapGet(SHeap* heap, SCliConn** p) { *p = container_of(minNode, SCliConn, node); return 0; } -int transHeapInsert(SHeap* heap, SCliConn* p) { +int32_t transHeapInsert(SHeap* heap, SCliConn* p) { // impl later if (p->inHeap == 1) { return TSDB_CODE_DUP_KEY; @@ -3747,7 +3753,7 @@ int transHeapInsert(SHeap* heap, SCliConn* p) { p->inHeap = 1; return 0; } -int transHeapDelete(SHeap* heap, SCliConn* p) { +int32_t transHeapDelete(SHeap* heap, SCliConn* p) { // impl later if (p->inHeap == 0) { return TSDB_CODE_INVALID_PARA; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index b940c494d8..d3f8da5ae4 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -330,6 +330,7 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { (void)taosThreadMutexLock(&item->mtx); QUEUE_PUSH(&item->qmsg, q); (void)taosThreadMutexUnlock(&item->mtx); + int ret = uv_async_send(async); if (ret != 0) { tError("failed to send async,reason:%s", uv_err_name(ret)); From 4e2c93f2620a0b67c35c19137156fee61858d4b8 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 21 Aug 2024 15:54:46 +0800 Subject: [PATCH 023/240] add network random error --- include/os/osFile.h | 26 ++++++++++++++++++++------ include/util/tdef.h | 9 ++------- source/libs/transport/src/thttp.c | 4 ++++ source/libs/transport/src/transCli.c | 9 ++++++++- source/libs/transport/src/transComm.c | 5 +++++ source/libs/transport/src/transSvr.c | 9 ++++++++- source/os/src/osFile.c | 4 ++-- source/os/src/osMemory.c | 4 ++-- 8 files changed, 51 insertions(+), 19 deletions(-) diff --git a/include/os/osFile.h b/include/os/osFile.h index 8bacb1bf7c..a56c54b086 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -120,15 +120,29 @@ int32_t taosSetFileHandlesLimit(); int32_t taosLinkFile(char *src, char *dst); -FILE* taosOpenCFile(const char* filename, const char* mode); -int taosSeekCFile(FILE* file, int64_t offset, int whence); -size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream ); -size_t taosWriteToCFile(const void* ptr, size_t size, size_t nitems, FILE* stream); -int taosCloseCFile(FILE *); -int taosSetAutoDelFile(char* path); +FILE *taosOpenCFile(const char *filename, const char *mode); +int taosSeekCFile(FILE *file, int64_t offset, int whence); +size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream); +size_t taosWriteToCFile(const void *ptr, size_t size, size_t nitems, FILE *stream); +int taosCloseCFile(FILE *); +int taosSetAutoDelFile(char *path); bool lastErrorIsFileNotExist(); +#ifdef BUILD_WITH_RAND_ERR +#define STUB_RAND_NETWORK_ERR(status) \ + do { \ + if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_NETWORK)) { \ + uint32_t r = taosRand() % tsRandErrDivisor; \ + if ((r + 1) <= tsRandErrChance) { \ + status = TSDB_CODE_RPC_NETWORK_UNAVAIL; \ + } \ + } \ + while (0) +#else +#define STUB_RAND_NETWORK_ERR(status) +#endif + #ifdef __cplusplus } #endif diff --git a/include/util/tdef.h b/include/util/tdef.h index 35c4adab50..f087c28684 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -294,7 +294,7 @@ typedef enum ELogicConditionType { #define TSDB_SHOW_SUBQUERY_LEN 1000 #define TSDB_LOG_VAR_LEN 32 -#define TSDB_MAX_EP_NUM 10 +#define TSDB_MAX_EP_NUM 10 #define TSDB_ARB_GROUP_MEMBER_NUM 2 #define TSDB_ARB_TOKEN_SIZE 32 @@ -568,12 +568,7 @@ enum { SND_WORKER_TYPE__UNIQUE, }; -enum { - RAND_ERR_MEMORY = 1, - RAND_ERR_FILE = 2, - // RAND_ERR_SCOPE_XXX... = 4, - // ... -}; +enum { RAND_ERR_MEMORY = 1, RAND_ERR_FILE = 2, RAND_ERR_NETWORK = 4 }; #define DEFAULT_HANDLE 0 #define MNODE_HANDLE 1 diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 908468f094..e517b8a0bc 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -345,6 +345,7 @@ static FORCE_INLINE void clientAllocBuffCb(uv_handle_t* handle, size_t suggested } static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { + STUB_RAND_NETWORK_ERR(nread); SHttpClient* cli = handle->data; if (nread < 0) { tError("http-report recv error:%s", uv_strerror(nread)); @@ -356,6 +357,7 @@ static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const } } static void clientSentCb(uv_write_t* req, int32_t status) { + STUB_RAND_NETWORK_ERR(status); SHttpClient* cli = req->data; if (status != 0) { tError("http-report failed to send data, reason: %s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr, @@ -367,6 +369,7 @@ static void clientSentCb(uv_write_t* req, int32_t status) { } else { tTrace("http-report succ to send data, chanId:%" PRId64 "", cli->chanId); } + status = uv_read_start((uv_stream_t*)&cli->tcp, clientAllocBuffCb, clientRecvCb); if (status != 0) { tError("http-report failed to recv data,reason:%s, dst:%s:%d, chanId:%" PRId64 "", uv_strerror(status), cli->addr, @@ -377,6 +380,7 @@ static void clientSentCb(uv_write_t* req, int32_t status) { } } static void clientConnCb(uv_connect_t* req, int32_t status) { + STUB_RAND_NETWORK_ERR(status); SHttpClient* cli = req->data; int64_t chanId = cli->chanId; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 862a74c72b..a5cc492b2b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -923,10 +923,12 @@ static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_ } } static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { - // impl later + STUB_RAND_NETWORK_ERR(nread); + if (handle->data == NULL) { return; } + SCliConn* conn = handle->data; SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { @@ -1117,6 +1119,8 @@ static bool cliHandleNoResp(SCliConn* conn) { return res; } static void cliSendCb(uv_write_t* req, int status) { + STUB_RAND_NETWORK_ERR(status); + SCliConn* pConn = transReqQueueRemove(req); if (pConn == NULL) return; @@ -1434,6 +1438,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { cliSendBatch(conn); } static void cliSendBatchCb(uv_write_t* req, int status) { + STUB_RAND_NETWORK_ERR(status); SCliConn* conn = req->data; SCliThrd* thrd = conn->hostThrd; SCliBatch* p = conn->pBatch; @@ -1523,6 +1528,8 @@ void cliConnCb(uv_connect_t* req, int status) { pConn->timer = NULL; } + STUB_RAND_NETWORK_ERR(status); + if (status != 0) { cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, pConn->dstAddr); if (timeout == false) { diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 5d82e157b3..aea8282d44 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -869,3 +869,8 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) { *ppBuf = pBuf; return len; } + +// int32_t transGenRandomError(int32_t status) { +// STUB_RAND_NETWORK_ERR(status) +// return status; +// } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index c1b934c812..84938126c3 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -493,6 +493,8 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { SSvrConn* conn = cli->data; SWorkThrd* pThrd = conn->hostThrd; + STUB_RAND_NETWORK_ERR(nread); + if (true == pThrd->quit) { tInfo("work thread received quit msg, destroy conn"); destroyConn(conn, true); @@ -553,6 +555,7 @@ void uvOnTimeoutCb(uv_timer_t* handle) { } void uvOnSendCb(uv_write_t* req, int status) { + STUB_RAND_NETWORK_ERR(status); SSvrConn* conn = transReqQueueRemove(req); if (conn == NULL) return; @@ -602,6 +605,7 @@ void uvOnSendCb(uv_write_t* req, int status) { } } static void uvOnPipeWriteCb(uv_write_t* req, int status) { + STUB_RAND_NETWORK_ERR(status); if (status == 0) { tTrace("success to dispatch conn to work thread"); } else { @@ -949,6 +953,7 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { } } void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { + STUB_RAND_NETWORK_ERR(nread); if (nread < 0) { if (nread != UV_EOF) { tError("read error %s", uv_err_name(nread)); @@ -1041,9 +1046,11 @@ void* transAcceptThread(void* arg) { return NULL; } void uvOnPipeConnectionCb(uv_connect_t* connect, int status) { + STUB_RAND_NETWORK_ERR(status); if (status != 0) { return; - } + }; + SWorkThrd* pThrd = container_of(connect, SWorkThrd, connect_req); (void)uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); } diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index a5df4f63f3..4f76dea5d3 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -906,7 +906,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { int32_t code = _fstat64(pFile->fd, &fileStat); #else struct stat fileStat; - int32_t code = fstat(pFile->fd, &fileStat); + int32_t code = fstat(pFile->fd, &fileStat); #endif if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -1614,7 +1614,7 @@ int taosSeekCFile(FILE *file, int64_t offset, int whence) { #ifdef WINDOWS return _fseeki64(file, offset, whence); #else - int code = fseeko(file, offset, whence); + int code = fseeko(file, offset, whence); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); } diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 7a5a547354..7e25d7c817 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -24,7 +24,7 @@ int32_t tsRandErrChance = 1; int64_t tsRandErrDivisor = 10001; -int64_t tsRandErrScope = (RAND_ERR_MEMORY | RAND_ERR_FILE); +int64_t tsRandErrScope = (RAND_ERR_MEMORY | RAND_ERR_FILE | RAND_ERR_NETWORK); threadlocal bool tsEnableRandErr = 0; #if defined(USE_TD_MEMORY) || defined(USE_ADDR2LINE) @@ -388,7 +388,7 @@ char *taosStrdup(const char *ptr) { } #endif - return tstrdup(ptr); + return tstrdup(ptr); #endif } From 16888801c75709de2a9c1a9c07a7c8bb05e0091c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 21 Aug 2024 16:26:32 +0800 Subject: [PATCH 024/240] fix mem leak --- source/client/src/clientImpl.c | 63 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 563d70ab08..6b8bf88030 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -15,8 +15,8 @@ #include "cJSON.h" #include "clientInt.h" -#include "clientMonitor.h" #include "clientLog.h" +#include "clientMonitor.h" #include "command.h" #include "scheduler.h" #include "tdatablock.h" @@ -28,7 +28,7 @@ #include "tref.h" #include "tsched.h" #include "tversion.h" -static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet); +static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet); static int32_t buildConnectMsg(SRequestObj* pRequest, SMsgSendInfo** pMsgSendInfo); static bool stringLengthCheck(const char* str, size_t maxsize) { @@ -68,15 +68,13 @@ bool chkRequestKilled(void* param) { return killed; } -void cleanupAppInfo() { - taosHashCleanup(appInfo.pInstMap); -} +void cleanupAppInfo() { taosHashCleanup(appInfo.pInstMap); } static int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param, SAppInstInfo* pAppInfo, int connType, STscObj** pTscObj); int32_t taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, - uint16_t port, int connType, STscObj** pObj) { + uint16_t port, int connType, STscObj** pObj) { TSC_ERR_RET(taos_init()); if (!validateUserName(user)) { TSC_ERR_RET(TSDB_CODE_TSC_INVALID_USER_LENGTH); @@ -126,7 +124,7 @@ int32_t taos_connect_internal(const char* ip, const char* user, const char* pass } SAppInstInfo** pInst = NULL; - int32_t code = taosThreadMutexLock(&appInfo.mutex); + int32_t code = taosThreadMutexLock(&appInfo.mutex); if (TSDB_CODE_SUCCESS != code) { tscError("failed to lock app info, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code))); TSC_ERR_RET(code); @@ -187,14 +185,14 @@ _return: return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst, connType, pObj); } -//SAppInstInfo* getAppInstInfo(const char* clusterKey) { -// SAppInstInfo** ppAppInstInfo = taosHashGet(appInfo.pInstMap, clusterKey, strlen(clusterKey)); -// if (ppAppInstInfo != NULL && *ppAppInstInfo != NULL) { -// return *ppAppInstInfo; -// } else { -// return NULL; -// } -//} +// SAppInstInfo* getAppInstInfo(const char* clusterKey) { +// SAppInstInfo** ppAppInstInfo = taosHashGet(appInfo.pInstMap, clusterKey, strlen(clusterKey)); +// if (ppAppInstInfo != NULL && *ppAppInstInfo != NULL) { +// return *ppAppInstInfo; +// } else { +// return NULL; +// } +// } void freeQueryParam(SSyncQueryParam* param) { if (param == NULL) return; @@ -432,7 +430,7 @@ int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList) { return TSDB_CODE_SUCCESS; } -int32_t qnodeRequired(SRequestObj* pRequest, bool *required) { +int32_t qnodeRequired(SRequestObj* pRequest, bool* required) { if (QUERY_POLICY_VNODE == tsQueryPolicy || QUERY_POLICY_CLIENT == tsQueryPolicy) { *required = false; return TSDB_CODE_SUCCESS; @@ -554,7 +552,7 @@ int32_t buildVnodePolicyNodeList(SRequestObj* pRequest, SArray** pNodeList, SArr if (NULL == nodeList) { return terrno; } - char* policy = (tsQueryPolicy == QUERY_POLICY_VNODE) ? "vnode" : "client"; + char* policy = (tsQueryPolicy == QUERY_POLICY_VNODE) ? "vnode" : "client"; int32_t dbNum = taosArrayGetSize(pDbVgList); for (int32_t i = 0; i < dbNum; ++i) { @@ -568,7 +566,7 @@ int32_t buildVnodePolicyNodeList(SRequestObj* pRequest, SArray** pNodeList, SArr } for (int32_t j = 0; j < vgNum; ++j) { - SVgroupInfo* pInfo = taosArrayGet(pVg, j); + SVgroupInfo* pInfo = taosArrayGet(pVg, j); if (NULL == pInfo) { taosArrayDestroy(nodeList); return TSDB_CODE_OUT_OF_RANGE; @@ -1022,7 +1020,7 @@ void returnToUser(SRequestObj* pRequest) { } } -static int32_t createResultBlock(TAOS_RES* pRes, int32_t numOfRows, SSDataBlock**pBlock) { +static int32_t createResultBlock(TAOS_RES* pRes, int32_t numOfRows, SSDataBlock** pBlock) { int64_t lastTs = 0; TAOS_FIELD* pResFields = taos_fetch_fields(pRes); int32_t numOfFields = taos_num_fields(pRes); @@ -1032,7 +1030,7 @@ static int32_t createResultBlock(TAOS_RES* pRes, int32_t numOfRows, SSDataBlock* return code; } - for(int32_t i = 0; i < numOfFields; ++i) { + for (int32_t i = 0; i < numOfFields; ++i) { SColumnInfoData colInfoData = createColumnInfoData(pResFields[i].type, pResFields[i].bytes, i + 1); code = blockDataAppendColInfo(*pBlock, &colInfoData); if (TSDB_CODE_SUCCESS != code) { @@ -1054,7 +1052,7 @@ static int32_t createResultBlock(TAOS_RES* pRes, int32_t numOfRows, SSDataBlock* lastTs = ts; } - for(int32_t j = 0; j < numOfFields; ++j) { + for (int32_t j = 0; j < numOfFields; ++j) { SColumnInfoData* pColInfoData = taosArrayGet((*pBlock)->pDataBlock, j); code = colDataSetVal(pColInfoData, i, pRow[j], false); if (TSDB_CODE_SUCCESS != code) { @@ -1069,7 +1067,7 @@ static int32_t createResultBlock(TAOS_RES* pRes, int32_t numOfRows, SSDataBlock* (*pBlock)->info.window.ekey = lastTs; (*pBlock)->info.rows = numOfRows; - tscDebug("lastKey:%"PRId64" numOfRows:%d from all vgroups", lastTs, numOfRows); + tscDebug("lastKey:%" PRId64 " numOfRows:%d from all vgroups", lastTs, numOfRows); return TSDB_CODE_SUCCESS; } @@ -1215,7 +1213,7 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue } break; case QUERY_EXEC_MODE_SCHEDULE: { - SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); + SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); if (NULL == pMnodeList) { code = terrno; break; @@ -1533,7 +1531,7 @@ int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* p } int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param, - SAppInstInfo* pAppInfo, int connType, STscObj** pTscObj) { + SAppInstInfo* pAppInfo, int connType, STscObj** pTscObj) { *pTscObj = NULL; int32_t code = createTscObj(user, auth, db, connType, pAppInfo, pTscObj); if (TSDB_CODE_SUCCESS != code) { @@ -1560,7 +1558,8 @@ int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __ta } int64_t transporterId = 0; - code = asyncSendMsgToServer((*pTscObj)->pAppInfo->pTransporter, &(*pTscObj)->pAppInfo->mgmtEp.epSet, &transporterId, body); + code = asyncSendMsgToServer((*pTscObj)->pAppInfo->pTransporter, &(*pTscObj)->pAppInfo->mgmtEp.epSet, &transporterId, + body); if (TSDB_CODE_SUCCESS != code) { destroyTscObj(*pTscObj); tscError("failed to send connect msg to server, code:%s", tstrerror(code)); @@ -1794,6 +1793,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { pMsg->code = TSDB_CODE_OUT_OF_MEMORY; rpcFreeCont(pMsg->pCont); destroySendMsgInfo(pMsg->info.ahandle); + taosMemoryFree(tEpSet); return; } arg->msg = *pMsg; @@ -1820,7 +1820,7 @@ TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, cons } STscObj* pObj = NULL; - int32_t code = taos_connect_internal(ip, user, NULL, auth, db, port, CONN_TYPE__QUERY, &pObj); + int32_t code = taos_connect_internal(ip, user, NULL, auth, db, port, CONN_TYPE__QUERY, &pObj); if (TSDB_CODE_SUCCESS == code) { int64_t* rid = taosMemoryCalloc(1, sizeof(int64_t)); if (NULL == rid) { @@ -1890,7 +1890,7 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) } SReqResultInfo* pResInfo = &pRequest->body.resInfo; - SSchedulerReq req = { .syncReq = true, .pFetchRes = (void**)&pResInfo->pData }; + SSchedulerReq req = {.syncReq = true, .pFetchRes = (void**)&pResInfo->pData}; pRequest->code = schedulerFetchRows(pRequest->body.queryJob, &req); if (pRequest->code != TSDB_CODE_SUCCESS) { @@ -2033,7 +2033,7 @@ int32_t getVersion1BlockMetaSize(const char* p, int32_t numOfCols) { } static int32_t estimateJsonLen(SReqResultInfo* pResultInfo, int32_t numOfCols, int32_t numOfRows) { - char* p = (char*)pResultInfo->pData; + char* p = (char*)pResultInfo->pData; int32_t blockVersion = *(int32_t*)p; // | version | total length | total rows | total columns | flag seg| block group id | column schema | each column @@ -2298,7 +2298,7 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 char* pStart = p; for (int32_t i = 0; i < numOfCols; ++i) { - if(blockVersion == BLOCK_VERSION_1){ + if (blockVersion == BLOCK_VERSION_1) { colLength[i] = htonl(colLength[i]); } if (colLength[i] >= dataLen) { @@ -2733,7 +2733,8 @@ void syncQueryFn(void* param, void* res, int32_t code) { (void)tsem_post(&pParam->sem); } -void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly, int8_t source) { +void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly, + int8_t source) { if (sql == NULL || NULL == fp) { terrno = TSDB_CODE_INVALID_PARA; if (fp) { @@ -2932,7 +2933,7 @@ void taosAsyncFetchImpl(SRequestObj* pRequest, __taos_async_fn_t fp, void* param 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); + pRequest->body.fetchFp(param, pRequest, code); } } From 0adc07e712779a8f034146238336ed5e6d3f0804 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 21 Aug 2024 17:14:52 +0800 Subject: [PATCH 025/240] fix mem problem --- source/libs/transport/src/transCli.c | 10 ++++++++-- source/libs/transport/src/transComm.c | 3 +++ source/libs/transport/src/transSvr.c | 9 +++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a5cc492b2b..66fedf07ac 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1315,6 +1315,12 @@ void cliSend(SCliConn* pConn) { uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); + if (req == NULL) { + tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType), + tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + cliHandleExcept(pConn, -1); + return; + } int status = uv_write(req, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); if (status != 0) { @@ -2224,13 +2230,13 @@ static void* cliWorkThread(void* arg) { SCliThrd* pThrd = (SCliThrd*)arg; pThrd->pid = taosGetSelfPthreadId(); - + tsEnableRandErr = true; (void)strtolower(threadName, pThrd->pTransInst->label); setThreadName(threadName); (void)uv_run(pThrd->loop, UV_RUN_DEFAULT); - tDebug("thread quit-thread:%08" PRId64, pThrd->pid); + tDebug("thread quit-thread:%08 " PRId64, pThrd->pid); return NULL; } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index aea8282d44..85d7470871 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -414,6 +414,9 @@ void transReqQueueInit(queue* q) { } void* transReqQueuePush(queue* q) { STransReq* req = taosMemoryCalloc(1, sizeof(STransReq)); + if (req == NULL) { + return NULL; + } req->wreq.data = req; QUEUE_PUSH(q, &req->q); return &req->wreq; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 84938126c3..e03d5ddc34 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -696,6 +696,14 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { transRefSrvHandle(pConn); uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); + if (req == NULL) { + if (!uv_is_closing((uv_handle_t*)(pConn->pTcp))) { + tError("conn %p failed to write data, reason:%s", pConn, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + pConn->broken = true; + transUnrefSrvHandle(pConn); + return; + } + } (void)uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); } static void uvStartSendResp(SSvrMsg* smsg) { @@ -1174,6 +1182,7 @@ static int32_t addHandleToAcceptloop(void* arg) { void* transWorkerThread(void* arg) { setThreadName("trans-svr-work"); SWorkThrd* pThrd = (SWorkThrd*)arg; + tsEnableRandErr = true; (void)uv_run(pThrd->loop, UV_RUN_DEFAULT); return NULL; From c35513a507d7ee839da979f15fc24dd58eba86bd Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 21 Aug 2024 19:19:39 +0800 Subject: [PATCH 026/240] fix mem problem --- include/os/osFile.h | 17 +++++++++-------- source/libs/transport/src/transSvr.c | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/os/osFile.h b/include/os/osFile.h index a56c54b086..536dee268a 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -130,14 +130,15 @@ int taosSetAutoDelFile(char *path); bool lastErrorIsFileNotExist(); #ifdef BUILD_WITH_RAND_ERR -#define STUB_RAND_NETWORK_ERR(status) \ - do { \ - if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_NETWORK)) { \ - uint32_t r = taosRand() % tsRandErrDivisor; \ - if ((r + 1) <= tsRandErrChance) { \ - status = TSDB_CODE_RPC_NETWORK_UNAVAIL; \ - } \ - } \ +#define STUB_RAND_NETWORK_ERR(ret) \ + do { \ + if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_NETWORK)) { \ + uint32_t r = taosRand() % tsRandErrDivisor; \ + if ((r + 1) <= tsRandErrChance) { \ + ret = TSDB_CODE_RPC_NETWORK_UNAVAIL; \ + uError("random network error: %s, %s", tstrerror(ret), __func__); \ + } \ + } \ while (0) #else #define STUB_RAND_NETWORK_ERR(status) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index e03d5ddc34..a3f8c65cba 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1191,6 +1191,7 @@ void* transWorkerThread(void* arg) { static FORCE_INLINE SSvrConn* createConn(void* hThrd) { int32_t code = 0; SWorkThrd* pThrd = hThrd; + STrans* pTransInst = pThrd->pTransInst; SSvrConn* pConn = (SSvrConn*)taosMemoryCalloc(1, sizeof(SSvrConn)); if (pConn == NULL) { @@ -1232,7 +1233,6 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _end); } - STrans* pTransInst = pThrd->pTransInst; pConn->refId = exh->refId; QUEUE_INIT(&exh->q); transRefSrvHandle(pConn); From ec3c967fe72d57bc635ac2b468a64b41e53117b2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 21 Aug 2024 19:52:15 +0800 Subject: [PATCH 027/240] fix mem problem --- source/os/src/osFile.c | 17 +++++++++-------- source/os/src/osMemory.c | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 4f76dea5d3..b468f87af6 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -66,14 +66,15 @@ typedef struct TdFile { #define FILE_WITH_LOCK 1 #ifdef BUILD_WITH_RAND_ERR -#define STUB_RAND_IO_ERR(ret) \ - if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_FILE)) { \ - uint32_t r = taosRand() % tsRandErrDivisor; \ - if ((r + 1) <= tsRandErrChance) { \ - errno = EIO; \ - terrno = TAOS_SYSTEM_ERROR(errno); \ - return (ret); \ - } \ +#define STUB_RAND_IO_ERR(ret) \ + if (tsEnableRandErr && (tsRandErrScope & RAND_ERR_FILE)) { \ + uint32_t r = taosRand() % tsRandErrDivisor; \ + if ((r + 1) <= tsRandErrChance) { \ + errno = EIO; \ + terrno = TAOS_SYSTEM_ERROR(errno); \ + uError("random io error: %s, %s", tstrerror(terrno), __func__); \ + return (ret); \ + } \ } #else #define STUB_RAND_IO_ERR(ret) diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 7e25d7c817..1c5963780a 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -308,6 +308,7 @@ void *taosMemoryCalloc(int64_t num, int64_t size) { uint32_t r = taosRand() % tsRandErrDivisor; if ((r + 1) <= tsRandErrChance) { terrno = TSDB_CODE_OUT_OF_MEMORY; + uError("random memory error: %s, %s", tstrerror(terrno), __func__); return NULL; } } From 1c85d3d9598d7e76ca16918246ab52df7d52449d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 22 Aug 2024 09:17:26 +0800 Subject: [PATCH 028/240] fix mem problem --- source/libs/transport/src/transSvr.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index a3f8c65cba..88cfd547b6 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -969,7 +969,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { // TODO(log other failure reason) tWarn("failed to create connect:%p, reason: %s", q, uv_err_name(nread)); taosMemoryFree(buf->base); - uv_close((uv_handle_t*)q, NULL); + // uv_close((uv_handle_t*)q, NULL); return; } // free memory allocated by @@ -982,32 +982,22 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { uv_pipe_t* pipe = (uv_pipe_t*)q; if (!uv_pipe_pending_count(pipe)) { tError("No pending count"); - uv_close((uv_handle_t*)q, NULL); + // uv_close((uv_handle_t*)q, NULL); return; } if (pThrd->quit) { tWarn("thread already received quit msg, ignore incoming conn"); - uv_close((uv_handle_t*)q, NULL); + // uv_close((uv_handle_t*)q, NULL); return; } SSvrConn* pConn = createConn(pThrd); if (pConn == NULL) { - uv_close((uv_handle_t*)q, 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; - if (uv_accept(q, (uv_stream_t*)(pConn->pTcp)) == 0) { uv_os_fd_t fd; (void)uv_fileno((const uv_handle_t*)pConn->pTcp, &fd); @@ -1239,9 +1229,6 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { 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)); From c41f7fe19d48ecb5e2c2d5c3f8c64b0af359132a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 22 Aug 2024 14:51:27 +0800 Subject: [PATCH 029/240] fix random_err crash --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 66fedf07ac..af828dd63c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2236,7 +2236,7 @@ static void* cliWorkThread(void* arg) { (void)uv_run(pThrd->loop, UV_RUN_DEFAULT); - tDebug("thread quit-thread:%08 " PRId64, pThrd->pid); + tDebug("thread quit-thread:%08" PRId64 "", pThrd->pid); return NULL; } From 920131559477794948c41c5241f18bc66d6512a8 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 22 Aug 2024 16:23:01 +0800 Subject: [PATCH 030/240] fix random_err crash --- source/dnode/mgmt/mgmt_mnode/src/mmWorker.c | 9 +++++---- source/libs/transport/src/transCli.c | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index fc070d0d05..0a0bd529bb 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -22,7 +22,7 @@ static inline int32_t mmAcquire(SMnodeMgmt *pMgmt) { int32_t code = 0; (void)taosThreadRwlockRdlock(&pMgmt->lock); if (pMgmt->stopped) { - code = -1; + code = TSDB_CODE_MNODE_NOT_FOUND; } else { (void)atomic_add_fetch_32(&pMgmt->refCount, 1); } @@ -134,16 +134,17 @@ int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { } int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { + int32_t code = 0; if (NULL == pMgmt->pMnode) { const STraceId *trace = &pMsg->info.traceId; dGError("msg:%p, stop to pre-process in mnode since mnode is NULL, type:%s", pMsg, TMSG_INFO(pMsg->msgType)); - return -1; + return TSDB_CODE_MND_MNODE_NOT_EXIST; } pMsg->info.node = pMgmt->pMnode; - if (mndPreProcessQueryMsg(pMsg) != 0) { + if ((code = mndPreProcessQueryMsg(pMsg)) != 0) { const STraceId *trace = &pMsg->info.traceId; dGError("msg:%p, failed to pre-process in mnode since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType)); - return -1; + return code; } return mmPutMsgToWorker(pMgmt, &pMgmt->queryWorker, pMsg); } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index af828dd63c..1a3afc03f9 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -961,7 +961,8 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { - int32_t code = 0; + int32_t code = 0; + SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); if (conn == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -1017,7 +1018,6 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { _failed: if (conn) { taosMemoryFree(conn->stream); - transReqQueueClear(&conn->wreqQueue); (void)transDestroyBuffer(&conn->readBuf); transQueueDestroy(&conn->cliMsgs); } From 2982a8ae511889e9330466f5c93952c2712bcb90 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 22 Aug 2024 19:32:20 +0800 Subject: [PATCH 031/240] fix random_err crash --- source/libs/transport/src/transCli.c | 106 +++++++++++++++++---------- source/libs/transport/src/transSvr.c | 21 +++--- 2 files changed, 79 insertions(+), 48 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1a3afc03f9..6d6336425d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -696,6 +696,11 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { plist = taosHashGet(pool, key, klen); SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); + if (nList == NULL) { + doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pMsg = NULL; + return NULL; + } QUEUE_INIT(&nList->msgQ); nList->numOfConn++; @@ -817,7 +822,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { cliDestroyConnMsgs(conn, false); - if (conn->list == NULL) { + if (conn->list == NULL && conn->dstAddr != NULL) { conn->list = taosHashGet((SHashObj*)pool, conn->dstAddr, strlen(conn->dstAddr)); } @@ -962,6 +967,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { int32_t code = 0; + int8_t registed = 0; SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); if (conn == NULL) { @@ -981,8 +987,24 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { code = TSDB_CODE_THIRDPARTY_ERROR; TAOS_CHECK_GOTO(code, NULL, _failed); } + + registed = 1; conn->stream->data = conn; + conn->connReq.data = conn; + + transReqQueueInit(&conn->wreqQueue); + QUEUE_INIT(&conn->q); + conn->hostThrd = pThrd; + conn->status = ConnNormal; + conn->broken = false; + + TAOS_CHECK_GOTO(transQueueInit(&conn->cliMsgs, NULL), NULL, _failed); + + TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); + + transRefCliHandle(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)); @@ -996,18 +1018,6 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { timer->data = conn; conn->timer = timer; - conn->connReq.data = conn; - transReqQueueInit(&conn->wreqQueue); - - 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); (void)atomic_add_fetch_32(&pThrd->connCount, 1); @@ -1016,12 +1026,16 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { *pCliConn = conn; return code; _failed: - if (conn) { - taosMemoryFree(conn->stream); - (void)transDestroyBuffer(&conn->readBuf); - transQueueDestroy(&conn->cliMsgs); + if (registed == 1) { + uv_close((uv_handle_t*)conn->stream, cliDestroy); + } else { + if (conn) { + taosMemoryFree(conn->stream); + (void)transDestroyBuffer(&conn->readBuf); + transQueueDestroy(&conn->cliMsgs); + } + taosMemoryFree(conn); } - taosMemoryFree(conn); return code; } static void cliDestroyConn(SCliConn* conn, bool clear) { @@ -1032,7 +1046,7 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { QUEUE_INIT(&conn->q); conn->broken = true; - if (conn->list == NULL) { + if (conn->list == NULL && conn->dstAddr) { conn->list = taosHashGet((SHashObj*)pThrd->pool, conn->dstAddr, strlen(conn->dstAddr)); } @@ -1287,19 +1301,19 @@ void cliSend(SCliConn* pConn) { STraceId* trace = &pMsg->info.traceId; - if (pTransInst->startTimer != NULL && pTransInst->startTimer(0, pMsg->msgType)) { - 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)); - tDebug("no available timer, create a timer %p", timer); - (void)uv_timer_init(pThrd->loop, timer); - } - timer->data = pConn; - pConn->timer = timer; + // if (pTransInst->startTimer != NULL && pTransInst->startTimer(0, pMsg->msgType)) { + // 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)); + // tDebug("no available timer, create a timer %p", 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)); - (void)uv_timer_start((uv_timer_t*)pConn->timer, cliReadTimeoutCb, TRANS_READ_TIMEOUT, 0); - } + // tGTrace("%s conn %p start timer for msg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType)); + // (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) { if (pTransInst->compressSize != -1 && pTransInst->compressSize < pMsg->contLen) { @@ -1385,7 +1399,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { 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); + uv_close((uv_handle_t*)conn->stream, cliDestroy); return; } @@ -1727,8 +1741,6 @@ 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)); - if (pResp->code == 0) { pResp->code = TSDB_CODE_RPC_BROKEN_LINK; } @@ -1869,6 +1881,12 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { (void)transQueuePush(&conn->cliMsgs, pMsg); conn->dstAddr = taosStrdup(addr); + 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; int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn, &ipaddr); @@ -2564,16 +2582,25 @@ static void cliSchedMsgToDebug(SCliMsg* pMsg, char* label) { return; } -static void cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { +static int32_t cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { STrans* pTransInst = pThrd->pTransInst; STransConnCtx* pCtx = pMsg->ctx; cliSchedMsgToDebug(pMsg, transLabel(pThrd->pTransInst)); STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + if (arg == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + arg->param1 = pMsg; arg->param2 = pThrd; - (void)transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); + SDelayTask* pTask = transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); + if (pTask == NULL) { + taosMemoryFree(arg); + return TSDB_CODE_OUT_OF_MEMORY; + } + return 0; } FORCE_INLINE bool cliTryExtractEpSet(STransMsg* pResp, SEpSet* dst) { @@ -2748,7 +2775,12 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } pMsg->sent = 0; - cliSchedMsgToNextNode(pMsg, pThrd); + code = cliSchedMsgToNextNode(pMsg, pThrd); + if (code != 0) { + pResp->code = code; + tError("failed to sched msg to next node, reason:%s", tstrerror(code)); + return false; + } return true; } int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 88cfd547b6..d4c98591d7 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1182,22 +1182,22 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { int32_t code = 0; SWorkThrd* pThrd = hThrd; STrans* pTransInst = pThrd->pTransInst; + int32_t lino; SSvrConn* pConn = (SSvrConn*)taosMemoryCalloc(1, sizeof(SSvrConn)); if (pConn == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); } transReqQueueInit(&pConn->wreqQueue); QUEUE_INIT(&pConn->queue); - QUEUE_PUSH(&pThrd->conn, &pConn->queue); if ((code = transQueueInit(&pConn->srvMsgs, NULL)) != 0) { - TAOS_CHECK_GOTO(code, NULL, _end); + TAOS_CHECK_GOTO(code, &lino, _end); } if ((code = transInitBuffer(&pConn->readBuf)) != 0) { - TAOS_CHECK_GOTO(code, NULL, _end); + TAOS_CHECK_GOTO(code, &lino, _end); } memset(&pConn->regArg, 0, sizeof(pConn->regArg)); @@ -1206,14 +1206,14 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle)); if (exh == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _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); + TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, &lino, _end); } QUEUE_INIT(&exh->q); @@ -1233,15 +1233,16 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { // 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); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _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); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _end); } pConn->pTcp->data = pConn; + QUEUE_PUSH(&pThrd->conn, &pConn->queue); return pConn; _end: @@ -1252,7 +1253,7 @@ _end: taosMemoryFree(pConn); pConn = NULL; } - tError("%s failed to create conn since %s" PRId64, transLabel(pTransInst), tstrerror(code)); + tError("%s failed to create conn since %s, lino:%d" PRId64, transLabel(pTransInst), tstrerror(code), lino); return NULL; } @@ -1895,5 +1896,3 @@ int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { } return code; } - -int32_t transGetConnInfo(void* thandle, STransHandleInfo* pConnInfo) { return -1; } From 58a6821d48a2cadb60cf90ee0786cd37f2a38ec4 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 22 Aug 2024 22:26:29 +0800 Subject: [PATCH 032/240] Merge branch 'fix/fixInitFailedLog2' into enh/TD-31494 --- source/libs/transport/inc/transComm.h | 8 +- source/libs/transport/src/transCli.c | 854 ++++++++++++++------------ 2 files changed, 450 insertions(+), 412 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index ad3ee0bfb1..f4d5fcfe16 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -162,7 +162,7 @@ typedef struct { void* task; int hThrdIdx; -} STransConnCtx; +} SReqCtx; #pragma pack(push, 1) @@ -318,9 +318,9 @@ void transUnrefCliHandle(void* handle); int32_t transReleaseCliHandle(void* handle); int32_t transReleaseSrvHandle(void* handle); -int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransCtx* pCtx); -int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp); -int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp, int8_t* epUpdated, +int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* pCtx); +int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp); +int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs); int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId); int32_t transFreeConnById(void* shandle, int64_t transpointId); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1f2b1fd88f..116904e9c7 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -65,7 +65,7 @@ typedef struct SCliConn { void* hostThrd; SConnBuffer readBuf; - STransQueue cliMsgs; + STransQueue reqMsgs; queue q; SConnList* list; @@ -92,18 +92,18 @@ typedef struct SCliConn { int32_t shareCnt; } SCliConn; -typedef struct SCliMsg { - STransConnCtx* ctx; - STransMsg msg; - queue q; - STransMsgType type; +typedef struct SCliReq { + SReqCtx* ctx; + STransMsg msg; + queue q; + STransMsgType type; int64_t refId; uint64_t st; int sent; //(0: no send, 1: alread sent) queue seqq; - int32_t seqNum; -} SCliMsg; + int32_t seq; +} SCliReq; typedef struct SCliThrd { TdThread thread; // tid @@ -131,7 +131,7 @@ typedef struct SCliThrd { SHashObj* batchCache; SHashObj* connHeapCache; - SCliMsg* stopMsg; + SCliReq* stopMsg; bool quit; } SCliThrd; @@ -185,7 +185,7 @@ static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); static int32_t allocConnRef(SCliConn* conn, bool update); -static int cliNotifyCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg); +static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); void cliResetConnTimer(SCliConn* conn); static int32_t cliCreateConn(SCliThrd* thrd, SCliConn** pCliConn); @@ -196,15 +196,15 @@ 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); +static int32_t cliPreCheckSessionLimitForMsg(SCliThrd* pThrd, char* addr, SCliReq** pReq); static void cliDestroyBatch(SCliBatch* pBatch); // cli util func -static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx); +static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx); static FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr); -static FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* resp); -static FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliMsg* pMsg, int32_t code); +static FORCE_INLINE int32_t cliBuildExceptResp(SCliReq* pReq, STransMsg* resp); +static FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliReq* pReq, int32_t code); static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ipaddr); static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn); @@ -217,19 +217,19 @@ static void cliHandleExcept(SCliConn* conn, int32_t code); static void cliReleaseUnfinishedMsg(SCliConn* conn); static void cliHandleFastFail(SCliConn* pConn, int status); -static void doNotifyCb(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code); +static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code); // handle req from app -static void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd); -static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd); -static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd); -static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd); +static void cliHandleReq(SCliReq* pReq, SCliThrd* pThrd); +static void cliHandleQuit(SCliReq* pReq, SCliThrd* pThrd); +static void cliHandleRelease(SCliReq* pReq, SCliThrd* pThrd); +static void cliHandleUpdate(SCliReq* pReq, SCliThrd* pThrd); static void cliDealReq(queue* h, SCliThrd* pThrd); static void cliBatchDealReq(queue* h, SCliThrd* pThrd); static void (*cliDealFunc[])(queue* h, SCliThrd* pThrd) = {cliDealReq, cliBatchDealReq}; -static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd); +static void cliHandleFreeById(SCliReq* pReq, SCliThrd* pThrd); -static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, +static void (*cliAsyncHandle[])(SCliReq* pReq, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL, cliHandleUpdate, cliHandleFreeById}; static FORCE_INLINE void destroyCmsg(void* cmsg); @@ -237,7 +237,7 @@ static FORCE_INLINE void destroyCmsg(void* cmsg); static FORCE_INLINE void destroyCmsgWrapper(void* arg, void* param); static FORCE_INLINE void destroyCmsgAndAhandle(void* cmsg); static FORCE_INLINE int cliRBChoseIdx(STrans* pInst); -static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx); +static FORCE_INLINE void transDestroyConnCtx(SReqCtx* ctx); static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); @@ -289,17 +289,17 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); #define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ do { \ - int i = 0, sz = transQueueSize(&conn->cliMsgs); \ + int i = 0, sz = transQueueSize(&conn->reqMsgs); \ for (; i < sz; i++) { \ - pMsg = transQueueGet(&conn->cliMsgs, i); \ - if (pMsg->ctx != NULL && (uint64_t)pMsg->ctx->ahandle == ahandle) { \ + pReq = transQueueGet(&conn->reqMsgs, i); \ + if (pReq->ctx != NULL && (uint64_t)pReq->ctx->ahandle == ahandle) { \ break; \ } \ } \ if (i == sz) { \ - pMsg = NULL; \ + pReq = NULL; \ } else { \ - pMsg = transQueueRm(&conn->cliMsgs, i); \ + pReq = transQueueRm(&conn->reqMsgs, i); \ } \ } while (0) @@ -307,7 +307,7 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); do { \ int i = 0; \ do { \ - pCliMsg = transQueueGet(&conn->cliMsgs, i++); \ + pCliMsg = transQueueGet(&conn->reqMsgs, i++); \ if (pCliMsg && 0 == pCliMsg->sent) { \ break; \ } \ @@ -351,8 +351,8 @@ static void* cliWorkThread(void* arg); static void cliReleaseUnfinishedMsg(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; - for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) { - SCliMsg* msg = transQueueGet(&conn->cliMsgs, i); + for (int i = 0; i < transQueueSize(&conn->reqMsgs); i++) { + SCliReq* msg = transQueueGet(&conn->reqMsgs, i); if (msg != NULL && msg->ctx != NULL && msg->ctx->ahandle != (void*)0x9527) { if (conn->ctx.freeFunc != NULL && msg->ctx->ahandle != NULL) { conn->ctx.freeFunc(msg->ctx->ahandle); @@ -363,12 +363,12 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { } destroyCmsg(msg); } - transQueueClear(&conn->cliMsgs); + transQueueClear(&conn->reqMsgs); memset(&conn->ctx, 0, sizeof(conn->ctx)); } bool cliMaySendCachedMsg(SCliConn* conn) { - if (!transQueueEmpty(&conn->cliMsgs)) { - SCliMsg* pCliMsg = NULL; + if (!transQueueEmpty(&conn->reqMsgs)) { + SCliReq* pCliMsg = NULL; CONN_GET_NEXT_SENDMSG(conn); cliSend(conn); return true; @@ -392,9 +392,9 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { queue* h = QUEUE_HEAD(&exh->q); QUEUE_REMOVE(h); taosWUnLockLatch(&exh->latch); - SCliMsg* t = QUEUE_DATA(h, SCliMsg, seqq); + SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); transCtxMerge(&conn->ctx, &t->ctx->appCtx); - (void)transQueuePush(&conn->cliMsgs, t); + (void)transQueuePush(&conn->reqMsgs, t); tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); (void)transReleaseExHandle(transGetRefMgt(), refId); cliSend(conn); @@ -420,23 +420,23 @@ void cliResetConnTimer(SCliConn* conn) { } void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } -SCliMsg* cliFindMsgBySeqnum(SCliConn* conn, int32_t seqNum) { - SCliMsg* pMsg = NULL; - for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) { - pMsg = transQueueGet(&conn->cliMsgs, i); - if (pMsg->seqNum == seqNum) { - transQueueRm(&conn->cliMsgs, i); +SCliReq* cliFindReqBySeq(SCliConn* conn, int32_t seq) { + SCliReq* pReq = NULL; + for (int i = 0; i < transQueueSize(&conn->reqMsgs); i++) { + pReq = transQueueGet(&conn->reqMsgs, i); + if (pReq->seq == seq) { + transQueueRm(&conn->reqMsgs, i); break; } } - if (pMsg == NULL) { + if (pReq == NULL) { ASSERT(0); } - return pMsg; + return pReq; } bool cliShouldAddConnToPool(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; - bool empty = transQueueEmpty(&conn->cliMsgs); + bool empty = transQueueEmpty(&conn->reqMsgs); if (empty) { (void)delConnFromHeapCache(pThrd->connHeapCache, conn); } @@ -472,18 +472,18 @@ void cliHandleResp_shareConn(SCliConn* conn) { transMsg.info.hasEpSet = pHead->hasEpSet; transMsg.info.cliVer = htonl(pHead->compatibilityVer); - SCliMsg* pMsg = cliFindMsgBySeqnum(conn, pHead->seqNum); - pMsg->seqNum = 0; + SCliReq* pReq = cliFindReqBySeq(conn, pHead->seqNum); + pReq->seq = 0; - STransConnCtx* pCtx = pMsg->ctx; + SReqCtx* pCtx = pReq->ctx; transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; STraceId* trace = &transMsg.info.traceId; - int32_t ret = cliNotifyCb(conn, &transMsg, pMsg); + int32_t ret = cliNotifyCb(conn, pReq, &transMsg); if (ret != 0) { return; } else { - destroyCmsg(pMsg); + destroyCmsg(pReq); } } void cliHandleResp(SCliConn* conn) { @@ -528,18 +528,18 @@ void cliHandleResp(SCliConn* conn) { transMsg.info.hasEpSet = pHead->hasEpSet; transMsg.info.cliVer = htonl(pHead->compatibilityVer); - SCliMsg* pMsg = NULL; - STransConnCtx* pCtx = NULL; + SCliReq* pReq = NULL; + SReqCtx* pCtx = NULL; if (CONN_NO_PERSIST_BY_APP(conn)) { - pMsg = transQueuePop(&conn->cliMsgs); + pReq = transQueuePop(&conn->reqMsgs); - pCtx = pMsg ? pMsg->ctx : NULL; + pCtx = pReq ? pReq->ctx : NULL; transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; tDebug("%s conn %p get ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); } else { uint64_t ahandle = (uint64_t)pHead->ahandle; CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); - if (pMsg == NULL) { + if (pReq == NULL) { transMsg.info.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType); tDebug("%s conn %p construct ahandle %p by %s, persist: 1", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle, TMSG_INFO(transMsg.msgType)); @@ -550,7 +550,7 @@ void cliHandleResp(SCliConn* conn) { transMsg.info.ahandle); } } else { - pCtx = pMsg->ctx; + pCtx = pReq->ctx; transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; tDebug("%s conn %p get ahandle %p, persist: 1", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); } @@ -577,14 +577,14 @@ void cliHandleResp(SCliConn* conn) { return; } - if (pMsg == NULL || (pMsg && pMsg->type != Release)) { - if (cliNotifyCb(conn, &transMsg, pMsg) != 0) { + if (pReq == NULL || (pReq && pReq->type != Release)) { + if (cliNotifyCb(conn, pReq, &transMsg) != 0) { return; } } - int64_t refId = (pMsg == NULL ? 0 : (int64_t)(pMsg->msg.info.handle)); + int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); tDebug("conn %p msg refId: %" PRId64 "", conn, refId); - destroyCmsg(pMsg); + destroyCmsg(pReq); if (cliConnSendSeqMsg(refId, conn)) { return; @@ -608,7 +608,7 @@ static void cliDestroyMsgInExhandle(int64_t refId) { while (!QUEUE_IS_EMPTY(&exh->q)) { queue* h = QUEUE_HEAD(&exh->q); QUEUE_REMOVE(h); - SCliMsg* t = QUEUE_DATA(h, SCliMsg, seqq); + SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); destroyCmsg(t); } taosWUnLockLatch(&exh->latch); @@ -617,7 +617,7 @@ static void cliDestroyMsgInExhandle(int64_t refId) { } void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { - if (transQueueEmpty(&pConn->cliMsgs)) { + if (transQueueEmpty(&pConn->reqMsgs)) { if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); @@ -629,26 +629,26 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { STrans* pInst = pThrd->pInst; bool once = false; do { - SCliMsg* pMsg = transQueuePop(&pConn->cliMsgs); + SCliReq* pReq = transQueuePop(&pConn->reqMsgs); - if (pMsg == NULL && once) { + if (pReq == NULL && once) { break; } - if (pMsg != NULL && REQUEST_NO_RESP(&pMsg->msg)) { - destroyCmsg(pMsg); + if (pReq != NULL && REQUEST_NO_RESP(&pReq->msg)) { + destroyCmsg(pReq); break; } - STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL; + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; STransMsg transMsg = {0}; transMsg.code = code == -1 ? (pConn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; - transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0; + transMsg.msgType = pReq ? pReq->msg.msgType + 1 : 0; transMsg.info.ahandle = NULL; transMsg.info.cliVer = pInst->compatibilityVer; - if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { + if (pReq == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { transMsg.info.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType); tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle, TMSG_INFO(transMsg.msgType)); @@ -660,29 +660,29 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { transMsg.info.ahandle); } } else { - transMsg.info.ahandle = (pMsg != NULL && pMsg->type != Release && pCtx) ? pCtx->ahandle : NULL; + transMsg.info.ahandle = (pReq != NULL && pReq->type != Release && pCtx) ? pCtx->ahandle : NULL; } if (pCtx == NULL || pCtx->pSem == NULL) { if (transMsg.info.ahandle == NULL) { - if (pMsg == NULL || REQUEST_NO_RESP(&pMsg->msg) || pMsg->type == Release) { - destroyCmsg(pMsg); + if (pReq == NULL || REQUEST_NO_RESP(&pReq->msg) || pReq->type == Release) { + destroyCmsg(pReq); once = true; continue; } } } - if (pMsg == NULL || (pMsg && pMsg->type != Release)) { - int64_t refId = (pMsg == NULL ? 0 : (int64_t)(pMsg->msg.info.handle)); + if (pReq == NULL || (pReq && pReq->type != Release)) { + int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); cliDestroyMsgInExhandle(refId); - if (cliNotifyCb(pConn, &transMsg, pMsg) != 0) { + if (cliNotifyCb(pConn, pReq, &transMsg) != 0) { return; } } - destroyCmsg(pMsg); + destroyCmsg(pReq); tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); - } while (!transQueueEmpty(&pConn->cliMsgs)); + } while (!transQueueEmpty(&pConn->reqMsgs)); if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); transUnrefCliHandle(pConn); } @@ -731,12 +731,12 @@ void* destroyConnPool(SCliThrd* pThrd) { queue* h = QUEUE_HEAD(&msglist->msgQ); QUEUE_REMOVE(h); - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); + SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - transDQCancel(pThrd->waitConnQueue, pMsg->ctx->task); - pMsg->ctx->task = NULL; + transDQCancel(pThrd->waitConnQueue, pReq->ctx->task); + pReq->ctx->task = NULL; - doNotifyCb(pMsg, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); + doNotifyCb(pReq, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); } taosMemoryFree(msglist); @@ -791,7 +791,7 @@ static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) { return conn; } -static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { +static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliReq** pReq) { void* pool = pThrd->pool; STrans* pInst = pThrd->pInst; size_t klen = strlen(key); @@ -803,8 +803,8 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); if (nList == NULL) { - // doNotifyApp(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; + // doNotifyApp(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pReq = NULL; return NULL; } QUEUE_INIT(&nList->msgQ); @@ -814,72 +814,72 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) { plist->list = nList; } - STraceId* trace = &(*pMsg)->msg.info.traceId; + STraceId* trace = &(*pReq)->msg.info.traceId; // no avaliable conn in pool if (QUEUE_IS_EMPTY(&plist->conns)) { SMsgList* list = plist->list; if ((list)->numOfConn >= pInst->connLimitNum) { - STraceId* trace = &(*pMsg)->msg.info.traceId; - if (pInst->notWaitAvaliableConn || (pInst->noDelayFp != NULL && pInst->noDelayFp((*pMsg)->msg.msgType))) { - tDebug("%s msg %s not to send, reason: %s", pInst->label, TMSG_INFO((*pMsg)->msg.msgType), + STraceId* trace = &(*pReq)->msg.info.traceId; + if (pInst->notWaitAvaliableConn || (pInst->noDelayFp != NULL && pInst->noDelayFp((*pReq)->msg.msgType))) { + tDebug("%s msg %s not to send, reason: %s", pInst->label, TMSG_INFO((*pReq)->msg.msgType), tstrerror(TSDB_CODE_RPC_NETWORK_BUSY)); - doNotifyCb(*pMsg, pThrd, TSDB_CODE_RPC_NETWORK_BUSY); - *pMsg = NULL; + doNotifyCb(*pReq, pThrd, TSDB_CODE_RPC_NETWORK_BUSY); + *pReq = NULL; return NULL; } STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); if (arg == NULL) { - doNotifyCb(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; + doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pReq = NULL; return NULL; } - arg->param1 = *pMsg; + arg->param1 = *pReq; arg->param2 = pThrd; SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); if (task == NULL) { taosMemoryFree(arg); - doNotifyCb(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; + doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pReq = NULL; return NULL; } - (*pMsg)->ctx->task = task; - tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pMsg)->msg.msgType)); - QUEUE_PUSH(&(list)->msgQ, &(*pMsg)->q); - *pMsg = NULL; + (*pReq)->ctx->task = task; + tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); + QUEUE_PUSH(&(list)->msgQ, &(*pReq)->q); + *pReq = NULL; } else { // send msg in delay queue if (!(QUEUE_IS_EMPTY(&(list)->msgQ))) { STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); if (arg == NULL) { - doNotifyCb(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; + doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pReq = NULL; return NULL; } - arg->param1 = *pMsg; + arg->param1 = *pReq; arg->param2 = pThrd; SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); if (task == NULL) { taosMemoryFree(arg); - doNotifyCb(*pMsg, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pMsg = NULL; + doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + *pReq = NULL; return NULL; } - (*pMsg)->ctx->task = task; - tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pMsg)->msg.msgType)); + (*pReq)->ctx->task = task; + tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); - QUEUE_PUSH(&(list)->msgQ, &(*pMsg)->q); + QUEUE_PUSH(&(list)->msgQ, &(*pReq)->q); queue* h = QUEUE_HEAD(&(list)->msgQ); QUEUE_REMOVE(h); - SCliMsg* ans = QUEUE_DATA(h, SCliMsg, q); + SCliReq* ans = QUEUE_DATA(h, SCliReq, q); - *pMsg = ans; + *pReq = ans; - trace = &(*pMsg)->msg.info.traceId; - tGTrace("%s msg %s pop from delay queue, start to send", pInst->label, TMSG_INFO((*pMsg)->msg.msgType)); + trace = &(*pReq)->msg.info.traceId; + tGTrace("%s msg %s pop from delay queue, start to send", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); transDQCancel(pThrd->waitConnQueue, ans->ctx->task); } list->numOfConn++; @@ -932,13 +932,13 @@ static void addConnToPool(void* pool, SCliConn* conn) { queue* h = QUEUE_HEAD(&(msgList)->msgQ); QUEUE_REMOVE(h); - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); + SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - transDQCancel(thrd->waitConnQueue, pMsg->ctx->task); - pMsg->ctx->task = NULL; + transDQCancel(thrd->waitConnQueue, pReq->ctx->task); + pReq->ctx->task = NULL; - transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - (void)transQueuePush(&conn->cliMsgs, pMsg); + transCtxMerge(&conn->ctx, &pReq->ctx->appCtx); + (void)transQueuePush(&conn->reqMsgs, pReq); conn->status = ConnNormal; cliSend(conn); @@ -1100,7 +1100,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { conn->status = ConnNormal; conn->broken = false; - TAOS_CHECK_GOTO(transQueueInit(&conn->cliMsgs, NULL), NULL, _failed); + TAOS_CHECK_GOTO(transQueueInit(&conn->reqMsgs, NULL), NULL, _failed); TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); @@ -1122,7 +1122,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { conn->connReq.data = conn; transReqQueueInit(&conn->wreqQueue); - TAOS_CHECK_GOTO(transQueueInit(&conn->cliMsgs, NULL), NULL, _failed); + TAOS_CHECK_GOTO(transQueueInit(&conn->reqMsgs, NULL), NULL, _failed); TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); @@ -1145,7 +1145,7 @@ _failed: if (conn) { taosMemoryFree(conn->stream); (void)transDestroyBuffer(&conn->readBuf); - transQueueDestroy(&conn->cliMsgs); + transQueueDestroy(&conn->reqMsgs); } taosMemoryFree(conn); } @@ -1214,11 +1214,11 @@ static void cliDestroy(uv_handle_t* handle) { } static bool cliHandleNoResp(SCliConn* conn) { bool res = false; - if (!transQueueEmpty(&conn->cliMsgs)) { - SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, 0); - if (REQUEST_NO_RESP(&pMsg->msg)) { - (void)transQueuePop(&conn->cliMsgs); - destroyCmsg(pMsg); + if (!transQueueEmpty(&conn->reqMsgs)) { + SCliReq* pReq = transQueueGet(&conn->reqMsgs, 0); + if (REQUEST_NO_RESP(&pReq->msg)) { + (void)transQueuePop(&conn->reqMsgs); + destroyCmsg(pReq); res = true; } if (res == true) { @@ -1239,16 +1239,16 @@ static void cliSendCb(uv_write_t* req, int status) { SCliConn* pConn = transReqQueueRemove(req); if (pConn == NULL) return; - SCliMsg* pMsg = transQueueGet(&pConn->cliMsgs, 0); - if (pMsg != NULL) { - int64_t cost = taosGetTimestampUs() - pMsg->st; + SCliReq* pReq = transQueueGet(&pConn->reqMsgs, 0); + if (pReq != NULL) { + int64_t cost = taosGetTimestampUs() - pReq->st; if (cost > 1000 * 50) { tTrace("%s conn %p send cost:%dus ", CONN_GET_INST_LABEL(pConn), pConn, (int)cost); } } - if (pMsg != NULL && pMsg->msg.contLen == 0 && pMsg->msg.pCont != 0) { - rpcFreeCont(pMsg->msg.pCont); - pMsg->msg.pCont = 0; + if (pReq != NULL && pReq->msg.contLen == 0 && pReq->msg.pCont != 0) { + rpcFreeCont(pReq->msg.pCont); + pReq->msg.pCont = 0; } if (status == 0) { @@ -1271,27 +1271,27 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { int32_t code = -1; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - while (!transQueueEmpty(&conn->cliMsgs)) { - SCliMsg* pMsg = transQueuePop(&conn->cliMsgs); - ASSERT(pMsg->type != Release); - ASSERT(REQUEST_NO_RESP(&pMsg->msg) == 0); + while (!transQueueEmpty(&conn->reqMsgs)) { + SCliReq* pReq = transQueuePop(&conn->reqMsgs); + ASSERT(pReq->type != Release); + ASSERT(REQUEST_NO_RESP(&pReq->msg) == 0); - STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL; + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; STransMsg transMsg = {0}; transMsg.code = code == -1 ? (conn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; - transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0; + transMsg.msgType = pReq ? pReq->msg.msgType + 1 : 0; transMsg.info.ahandle = NULL; transMsg.info.cliVer = pInst->compatibilityVer; transMsg.info.ahandle = pCtx->ahandle; - pMsg->seqNum = 0; - code = cliNotifyCb(conn, &transMsg, pMsg); + pReq->seqNum = 0; + code = cliNotifyCb(conn, pReq, &transMsg); if (code != 0) { continue; } else { // already notify user - destroyCmsg(pMsg); + destroyCmsg(pReq); } } @@ -1314,7 +1314,7 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { void cliSendBatch_shareConn(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - int32_t size = transQueueSize(&pConn->cliMsgs); + int32_t size = transQueueSize(&pConn->reqMsgs); int32_t totalLen = 0; if (size == 0) { @@ -1327,32 +1327,32 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int j = 0; for (int i = 0; i < size; i++) { - SCliMsg* pCliMsg = transQueueGet(&pConn->cliMsgs, i); + SCliReq* pCliMsg = transQueueGet(&pConn->reqMsgs, i); if (pCliMsg->sent == 1) { continue; } - STransConnCtx* pCtx = pCliMsg->ctx; + SReqCtx* pCtx = pCliMsg->ctx; pConn->seq++; - STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg); - if (pMsg->pCont == 0) { - pMsg->pCont = (void*)rpcMallocCont(0); - pMsg->contLen = 0; + STransMsg* pReq = (STransMsg*)(&pCliMsg->msg); + if (pReq->pCont == 0) { + pReq->pCont = (void*)rpcMallocCont(0); + pReq->contLen = 0; } - int msgLen = transMsgLenFromCont(pMsg->contLen); + int msgLen = transMsgLenFromCont(pReq->contLen); - STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); + STransMsgHead* pHead = transHeadFromCont(pReq->pCont); if (pHead->comp == 0) { pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; - pHead->noResp = REQUEST_NO_RESP(pMsg) ? 1 : 0; - pHead->persist = REQUEST_PERSIS_HANDLE(pMsg) ? 1 : 0; - pHead->msgType = pMsg->msgType; + pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; + pHead->persist = REQUEST_PERSIS_HANDLE(pReq) ? 1 : 0; + pHead->msgType = pReq->msgType; pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; memcpy(pHead->user, pInst->user, strlen(pInst->user)); - pHead->traceId = pMsg->info.traceId; + pHead->traceId = pReq->info.traceId; pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->version = TRANS_VER; pHead->compatibilityVer = htonl(pInst->compatibilityVer); @@ -1361,8 +1361,8 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pHead->seqNum = pConn->seq; if (pHead->comp == 0) { - if (pInst->compressSize != -1 && pInst->compressSize < pMsg->contLen) { - msgLen = transCompressMsg(pMsg->pCont, pMsg->contLen) + sizeof(STransMsgHead); + if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { + msgLen = transCompressMsg(pReq->pCont, pReq->contLen) + sizeof(STransMsgHead); pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); } } else { @@ -1402,42 +1402,42 @@ void cliSendBatch(SCliConn* pConn) { int i = 0; queue* h = NULL; QUEUE_FOREACH(h, &pBatch->wq) { - SCliMsg* pCliMsg = QUEUE_DATA(h, SCliMsg, q); + SCliReq* pCliMsg = QUEUE_DATA(h, SCliReq, q); - STransConnCtx* pCtx = pCliMsg->ctx; + SReqCtx* pCtx = pCliMsg->ctx; - STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg); - if (pMsg->pCont == 0) { - pMsg->pCont = (void*)rpcMallocCont(0); - if (pMsg->pCont == NULL) { + STransMsg* pReq = (STransMsg*)(&pCliMsg->msg); + if (pReq->pCont == 0) { + pReq->pCont = (void*)rpcMallocCont(0); + if (pReq->pCont == NULL) { code = TSDB_CODE_OUT_OF_BUFFER; tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); goto _exception; } - pMsg->contLen = 0; + pReq->contLen = 0; } - int msgLen = transMsgLenFromCont(pMsg->contLen); - STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); + int msgLen = transMsgLenFromCont(pReq->contLen); + STransMsgHead* pHead = transHeadFromCont(pReq->pCont); if (pHead->comp == 0) { pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; - pHead->noResp = REQUEST_NO_RESP(pMsg) ? 1 : 0; - pHead->persist = REQUEST_PERSIS_HANDLE(pMsg) ? 1 : 0; - pHead->msgType = pMsg->msgType; + pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; + pHead->persist = REQUEST_PERSIS_HANDLE(pReq) ? 1 : 0; + pHead->msgType = pReq->msgType; pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; memcpy(pHead->user, pInst->user, strlen(pInst->user)); - pHead->traceId = pMsg->info.traceId; + pHead->traceId = pReq->info.traceId; pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->version = TRANS_VER; pHead->compatibilityVer = htonl(pInst->compatibilityVer); } pHead->timestamp = taosHton64(taosGetTimestampUs()); - if (pHead->comp == 0 && pMsg->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { - if (pInst->compressSize != -1 && pInst->compressSize < pMsg->contLen) { - msgLen = transCompressMsg(pMsg->pCont, pMsg->contLen) + sizeof(STransMsgHead); + if (pHead->comp == 0 && pReq->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { + if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { + msgLen = transCompressMsg(pReq->pCont, pReq->contLen) + sizeof(STransMsgHead); pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); } } else { @@ -1475,37 +1475,37 @@ void cliSend(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - if (transQueueEmpty(&pConn->cliMsgs)) { + if (transQueueEmpty(&pConn->reqMsgs)) { tError("%s conn %p not msg to send", pInst->label, pConn); cliHandleExcept(pConn, -1); return; } - SCliMsg* pCliMsg = NULL; + SCliReq* pCliMsg = NULL; CONN_GET_NEXT_SENDMSG(pConn); pCliMsg->sent = 1; - STransConnCtx* pCtx = pCliMsg->ctx; + SReqCtx* pCtx = pCliMsg->ctx; - STransMsg* pMsg = (STransMsg*)(&pCliMsg->msg); - if (pMsg->pCont == 0) { - pMsg->pCont = (void*)rpcMallocCont(0); - tDebug("malloc memory: %p", pMsg->pCont); - pMsg->contLen = 0; + STransMsg* pReq = (STransMsg*)(&pCliMsg->msg); + if (pReq->pCont == 0) { + pReq->pCont = (void*)rpcMallocCont(0); + tDebug("malloc memory: %p", pReq->pCont); + pReq->contLen = 0; } - int msgLen = transMsgLenFromCont(pMsg->contLen); - STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); + int msgLen = transMsgLenFromCont(pReq->contLen); + STransMsgHead* pHead = transHeadFromCont(pReq->pCont); if (pHead->comp == 0) { pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; - pHead->noResp = REQUEST_NO_RESP(pMsg) ? 1 : 0; - pHead->persist = REQUEST_PERSIS_HANDLE(pMsg) ? 1 : 0; - pHead->msgType = pMsg->msgType; + pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; + pHead->persist = REQUEST_PERSIS_HANDLE(pReq) ? 1 : 0; + pHead->msgType = pReq->msgType; pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; memcpy(pHead->user, pInst->user, strlen(pInst->user)); - pHead->traceId = pMsg->info.traceId; + pHead->traceId = pReq->info.traceId; pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->version = TRANS_VER; pHead->compatibilityVer = htonl(pInst->compatibilityVer); @@ -1516,9 +1516,9 @@ void cliSend(SCliConn* pConn) { CONN_SET_PERSIST_BY_APP(pConn); } - STraceId* trace = &pMsg->info.traceId; + STraceId* trace = &pReq->info.traceId; - if (pInst->startTimer != NULL && pInst->startTimer(0, pMsg->msgType)) { + if (pInst->startTimer != NULL && pInst->startTimer(0, pReq->msgType)) { 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)); @@ -1529,9 +1529,9 @@ void cliSend(SCliConn* pConn) { pConn->timer = timer; } - if (pHead->comp == 0 && pMsg->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { - if (pInst->compressSize != -1 && pInst->compressSize < pMsg->contLen) { - msgLen = transCompressMsg(pMsg->pCont, pMsg->contLen) + sizeof(STransMsgHead); + if (pHead->comp == 0 && pReq->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { + if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { + msgLen = transCompressMsg(pReq->pCont, pReq->contLen) + sizeof(STransMsgHead); pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); } } else { @@ -1544,7 +1544,7 @@ void cliSend(SCliConn* pConn) { uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); if (req == NULL) { - tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType), + tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), tstrerror(TSDB_CODE_OUT_OF_MEMORY)); cliHandleExcept(pConn, -1); return; @@ -1552,7 +1552,7 @@ void cliSend(SCliConn* pConn) { int status = uv_write(req, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); if (status != 0) { - tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType), + tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), uv_err_name(status)); cliHandleExcept(pConn, -1); } @@ -1567,7 +1567,7 @@ static void cliDestroyBatch(SCliBatch* pBatch) { queue* h = QUEUE_HEAD(&pBatch->wq); QUEUE_REMOVE(h); - SCliMsg* p = QUEUE_DATA(h, SCliMsg, q); + SCliReq* p = QUEUE_DATA(h, SCliReq, q); destroyCmsg(p); } SCliBatchList* p = pBatch->pList; @@ -1715,11 +1715,11 @@ static void cliSendBatchCb(uv_write_t* req, int status) { static void cliHandleFastFail_resp(SCliConn* pConn, int status) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - SCliMsg* pMsg = transQueueGet(&pConn->cliMsgs, 0); + SCliReq* pReq = transQueueGet(&pConn->reqMsgs, 0); - STraceId* trace = &pMsg->msg.info.traceId; + STraceId* trace = &pReq->msg.info.traceId; tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), - TMSG_INFO(pMsg->msg.msgType), pConn, pConn->dstAddr, uv_strerror(status)); + TMSG_INFO(pReq->msg.msgType), pConn, pConn->dstAddr, uv_strerror(status)); } static void cliHandleFastFail_noresp(SCliConn* pConn, int status) { @@ -1788,17 +1788,17 @@ void cliConnCb(uv_connect_t* req, int status) { return cliSend(pConn); } -static void doNotifyCb(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code) { - STransConnCtx* pCtx = pMsg->ctx; - STrans* pInst = pThrd->pInst; +static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code) { + SReqCtx* pCtx = pReq->ctx; + STrans* pInst = pThrd->pInst; STransMsg transMsg = {0}; transMsg.contLen = 0; transMsg.pCont = NULL; transMsg.code = code; - transMsg.msgType = pMsg->msg.msgType + 1; - transMsg.info.ahandle = pMsg->ctx->ahandle; - transMsg.info.traceId = pMsg->msg.info.traceId; + transMsg.msgType = pReq->msg.msgType + 1; + transMsg.info.ahandle = pReq->ctx->ahandle; + transMsg.info.traceId = pReq->msg.info.traceId; transMsg.info.hasEpSet = false; transMsg.info.cliVer = pInst->compatibilityVer; if (pCtx->pSem != NULL) { @@ -1810,27 +1810,27 @@ static void doNotifyCb(SCliMsg* pMsg, SCliThrd* pThrd, int32_t code) { pInst->cfp(pInst->parent, &transMsg, NULL); } - destroyCmsg(pMsg); + destroyCmsg(pReq); } -static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd) { +static void cliHandleQuit(SCliReq* pReq, SCliThrd* pThrd) { if (!transAsyncPoolIsEmpty(pThrd->asyncPool)) { - pThrd->stopMsg = pMsg; + pThrd->stopMsg = pReq; return; } pThrd->stopMsg = NULL; pThrd->quit = true; tDebug("cli work thread %p start to quit", pThrd); - destroyCmsg(pMsg); + destroyCmsg(pReq); (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); +static void cliHandleRelease(SCliReq* pReq, SCliThrd* pThrd) { + int64_t refId = (int64_t)(pReq->msg.info.handle); SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); if (exh == NULL) { tDebug("%" PRId64 " already released", refId); - destroyCmsg(pMsg); + destroyCmsg(pReq); return; } @@ -1843,27 +1843,27 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) { if (T_REF_VAL_GET(conn) == 2) { transUnrefCliHandle(conn); - if (!transQueuePush(&conn->cliMsgs, pMsg)) { + if (!transQueuePush(&conn->reqMsgs, pReq)) { return; } cliSend(conn); } else { tError("%s conn %p already released", CONN_GET_INST_LABEL(conn), conn); - destroyCmsg(pMsg); + destroyCmsg(pReq); } } -static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd) { - STransConnCtx* pCtx = pMsg->ctx; +static void cliHandleUpdate(SCliReq* pReq, SCliThrd* pThrd) { + SReqCtx* pCtx = pReq->ctx; pThrd->cvtAddr = pCtx->cvtAddr; - destroyCmsg(pMsg); + destroyCmsg(pReq); } -static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) { +static void cliHandleFreeById(SCliReq* pReq, SCliThrd* pThrd) { int32_t code = 0; - int64_t refId = (int64_t)(pMsg->msg.info.handle); + int64_t refId = (int64_t)(pReq->msg.info.handle); SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); if (exh == NULL) { tDebug("id %" PRId64 " already released", refId); - destroyCmsg(pMsg); + destroyCmsg(pReq); return; } @@ -1876,7 +1876,7 @@ static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) { } tDebug("do free conn %p by id %" PRId64 "", conn, refId); - int32_t size = transQueueSize(&conn->cliMsgs); + int32_t size = transQueueSize(&conn->reqMsgs); if (size == 0) { // already recv, and notify upper layer TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); @@ -1892,14 +1892,14 @@ _exception: (void)transReleaseExHandle(transGetRefMgt(), refId); (void)transReleaseExHandle(transGetRefMgt(), refId); (void)transRemoveExHandle(transGetRefMgt(), refId); - destroyCmsg(pMsg); + destroyCmsg(pReq); } -SCliConn* cliGetConn(SCliMsg** pMsg, SCliThrd* pThrd, bool* ignore, char* addr) { - STransConnCtx* pCtx = (*pMsg)->ctx; - SCliConn* conn = NULL; +SCliConn* cliGetConn(SCliReq** pReq, SCliThrd* pThrd, bool* ignore, char* addr) { + SReqCtx* pCtx = (*pReq)->ctx; + SCliConn* conn = NULL; - int64_t refId = (int64_t)((*pMsg)->msg.info.handle); + int64_t refId = (int64_t)((*pReq)->msg.info.handle); if (refId != 0) { SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); if (exh == NULL) { @@ -1911,7 +1911,7 @@ SCliConn* cliGetConn(SCliMsg** pMsg, SCliThrd* pThrd, bool* ignore, char* addr) conn = exh->handle; taosRUnLockLatch(&exh->latch); if (conn == NULL) { - conn = getConnFromPool2(pThrd, addr, pMsg); + conn = getConnFromPool2(pThrd, addr, pReq); if (conn != NULL) specifyConnRef(conn, true, refId); } (void)transReleaseExHandle(transGetRefMgt(), refId); @@ -1919,7 +1919,7 @@ SCliConn* cliGetConn(SCliMsg** pMsg, SCliThrd* pThrd, bool* ignore, char* addr) return conn; }; - conn = getConnFromPool2(pThrd, addr, pMsg); + conn = getConnFromPool2(pThrd, addr, pReq); if (conn != NULL) { tTrace("%s conn %p get from conn pool:%p", CONN_GET_INST_LABEL(conn), conn, pThrd->pool); } else { @@ -1945,30 +1945,30 @@ FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr) return TSDB_CODE_RPC_FQDN_ERROR; } -FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, STransConnCtx* pCtx) { +FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx) { if (code != 0) return false; return transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet) ? false : true; } -FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) { - if (pMsg == NULL) return -1; +FORCE_INLINE int32_t cliBuildExceptResp(SCliReq* pReq, STransMsg* pResp) { + if (pReq == NULL) return -1; 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; + pResp->msgType = pReq->msg.msgType + 1; + pResp->info.ahandle = pReq->ctx ? pReq->ctx->ahandle : NULL; + pResp->info.traceId = pReq->msg.info.traceId; return 0; } -FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliMsg* pMsg, int32_t code) { +FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliReq* pReq, int32_t code) { STrans* pInst = pThrd->pInst; STransMsg resp = {.code = code}; - code = cliBuildExceptResp(pMsg, &resp); + code = cliBuildExceptResp(pReq, &resp); if (code != 0) { return code; } @@ -2036,15 +2036,15 @@ static void cliMayUpdateFqdnCache(SHashObj* cache, char* dst) { static void doFreeTimeoutMsg(void* param) { STaskArg* arg = param; - SCliMsg* pMsg = arg->param1; + SCliReq* pReq = arg->param1; SCliThrd* pThrd = arg->param2; STrans* pInst = pThrd->pInst; - QUEUE_REMOVE(&pMsg->q); - STraceId* trace = &pMsg->msg.info.traceId; + QUEUE_REMOVE(&pReq->q); + STraceId* trace = &pReq->msg.info.traceId; - tGTrace("%s msg %s cannot get available conn after timeout", pInst->label, TMSG_INFO(pMsg->msg.msgType)); - doNotifyCb(pMsg, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); + tGTrace("%s msg %s cannot get available conn after timeout", pInst->label, TMSG_INFO(pReq->msg.msgType)); + doNotifyCb(pReq, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); taosMemoryFree(arg); } @@ -2115,21 +2115,21 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { return code; } -void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { +void cliHandleReq__shareConn(SCliReq* pReq, SCliThrd* pThrd) { int32_t code = 0; - STraceId* trace = &pMsg->msg.info.traceId; + STraceId* trace = &pReq->msg.info.traceId; STrans* pInst = pThrd->pInst; - code = cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); + code = cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); if (code != 0) { // notifyCb - destroyCmsg(pMsg); + destroyCmsg(pReq); return; } char addr[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); + CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); SCliConn* pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); if (pConn == NULL) { @@ -2138,12 +2138,12 @@ void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { pConn = getConnFromPool(pThrd, addr, &ignore); if (pConn != NULL) { addConnToHeapCache(pThrd->connHeapCache, pConn); - transQueuePush(&pConn->cliMsgs, pMsg); + transQueuePush(&pConn->reqMsgs, pReq); return cliSendBatch_shareConn(pConn); } } else { tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); - transQueuePush(&pConn->cliMsgs, pMsg); + transQueuePush(&pConn->reqMsgs, pReq); cliSendBatch_shareConn(pConn); return; } @@ -2152,57 +2152,57 @@ void cliHandleReq__shareConn(SCliMsg* pMsg, SCliThrd* pThrd) { pConn->dstAddr = taosStrdup(addr); code = addConnToHeapCache(pThrd->connHeapCache, pConn); - transQueuePush(&pConn->cliMsgs, pMsg); - return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pMsg->ctx->epSet), EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet)); + transQueuePush(&pConn->reqMsgs, pReq); + return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); } -void cliHandleReq__noShareConn(SCliMsg* pMsg, SCliThrd* pThrd) { +void cliHandleReq__noShareConn(SCliReq* pReq, SCliThrd* pThrd) { int32_t code; STrans* pInst = pThrd->pInst; - code = cliMayCvtFqdnToIp(&pMsg->ctx->epSet, &pThrd->cvtAddr); + code = cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); if (code != 0) { // notifyCb - destroyCmsg(pMsg); + destroyCmsg(pReq); } - char* fqdn = EPSET_GET_INUSE_IP(&pMsg->ctx->epSet); - uint16_t port = EPSET_GET_INUSE_PORT(&pMsg->ctx->epSet); + char* fqdn = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); + uint16_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); char addr[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(addr, fqdn, port); bool ignore = false; - SCliConn* conn = cliGetConn(&pMsg, pThrd, &ignore, addr); + SCliConn* conn = cliGetConn(&pReq, pThrd, &ignore, addr); if (ignore == true) { // persist conn already release by server STransMsg resp = {0}; - if (pMsg->type != Release) { - (void)cliBuildExceptRespAndNotifyCb(pThrd, pMsg, 0); + if (pReq->type != Release) { + (void)cliBuildExceptRespAndNotifyCb(pThrd, pReq, 0); } - destroyCmsg(pMsg); + destroyCmsg(pReq); return; } - if (conn == NULL && pMsg == NULL) { + if (conn == NULL && pReq == NULL) { return; } - STraceId* trace = &pMsg->msg.info.traceId; + STraceId* trace = &pReq->msg.info.traceId; if (conn != NULL) { - transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - (void)transQueuePush(&conn->cliMsgs, pMsg); + transCtxMerge(&conn->ctx, &pReq->ctx->appCtx); + (void)transQueuePush(&conn->reqMsgs, pReq); cliSend(conn); } else { code = cliCreateConn(pThrd, &conn); if (code != 0) { tError("%s failed to create conn, reason:%s", pInst->label, tstrerror(code)); - (void)cliBuildExceptRespAndNotifyCb(pThrd, pMsg, code); - destroyCmsg(pMsg); + (void)cliBuildExceptRespAndNotifyCb(pThrd, pReq, code); + destroyCmsg(pReq); return; } - specifyConnRef(conn, true, (int64_t)pMsg->msg.info.handle); + specifyConnRef(conn, true, (int64_t)pReq->msg.info.handle); - transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - (void)transQueuePush(&conn->cliMsgs, pMsg); + transCtxMerge(&conn->ctx, &pReq->ctx->appCtx); + (void)transQueuePush(&conn->reqMsgs, pReq); conn->dstAddr = taosStrdup(addr); if (conn->dstAddr == NULL) { @@ -2261,12 +2261,12 @@ void cliHandleReq__noShareConn(SCliMsg* pMsg, SCliThrd* pThrd) { tGTrace("%s conn %p ready", pInst->label, conn); } -void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { +void cliHandleReq(SCliReq* pReq, SCliThrd* pThrd) { STrans* pInst = pThrd->pInst; if (pInst->shareConn == 1) { - return cliHandleReq__shareConn(pMsg, pThrd); + return cliHandleReq__shareConn(pReq, pThrd); } else { - return cliHandleReq__noShareConn(pMsg, pThrd); + return cliHandleReq__noShareConn(pReq, pThrd); } } @@ -2277,13 +2277,13 @@ static void cliDealReq(queue* wq, SCliThrd* pThrd) { queue* h = QUEUE_HEAD(wq); QUEUE_REMOVE(h); - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); + SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - if (pMsg->type == Quit) { - pThrd->stopMsg = pMsg; + if (pReq->type == Quit) { + pThrd->stopMsg = pReq; continue; } - (*cliAsyncHandle[pMsg->type])(pMsg, pThrd); + (*cliAsyncHandle[pReq->type])(pReq, pThrd); count++; } if (count >= 2) { @@ -2303,9 +2303,9 @@ SCliBatch* cliGetHeadFromList(SCliBatchList* pList) { SCliBatch* batch = QUEUE_DATA(hr, SCliBatch, listq); return batch; } -static void cliBuildBatch(SCliMsg* pMsg, queue* h, SCliThrd* pThrd) { - STrans* pInst = pThrd->pInst; - STransConnCtx* pCtx = pMsg->ctx; +static void cliBuildBatch(SCliReq* pReq, queue* h, SCliThrd* pThrd) { + STrans* pInst = pThrd->pInst; + SReqCtx* pCtx = pReq->ctx; return; } static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, uint32_t port) { @@ -2348,7 +2348,7 @@ static void destroyBatchList(SCliBatchList* pList) { taosMemoryFree(pList->dst); taosMemoryFree(pList); } -static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliMsg* pMsg) { +static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliReq* pReq) { SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); if (pBatch == NULL) { tError("failed to create batch, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); @@ -2358,9 +2358,9 @@ static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliMsg* p QUEUE_INIT(&pBatch->wq); QUEUE_INIT(&pBatch->listq); - QUEUE_PUSH(&pBatch->wq, &pMsg->q); + QUEUE_PUSH(&pBatch->wq, &pReq->q); pBatch->wLen += 1; - pBatch->batchSize = pMsg->msg.contLen; + pBatch->batchSize = pReq->msg.contLen; pBatch->pList = pList; QUEUE_PUSH(&pList->wq, &pBatch->listq); @@ -2378,15 +2378,15 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { queue* h = QUEUE_HEAD(wq); QUEUE_REMOVE(h); - SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); + SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { - cliBuildBatch(pMsg, h, pThrd); + if (pReq->type == Normal && REQUEST_NO_RESP(&pReq->msg)) { + cliBuildBatch(pReq, h, pThrd); continue; } - if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) { - STransConnCtx* pCtx = pMsg->ctx; + if (pReq->type == Normal && REQUEST_NO_RESP(&pReq->msg)) { + SReqCtx* pCtx = pReq->ctx; char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet); uint32_t port = EPSET_GET_INUSE_PORT(&pCtx->epSet); @@ -2398,17 +2398,17 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { SCliBatchList* pBatchList = NULL; code = createBatchList(&pBatchList, key, ip, port); if (code != 0) { - destroyCmsg(pMsg); + destroyCmsg(pReq); continue; } pBatchList->batchLenLimit = pInst->batchSize; SCliBatch* pBatch = NULL; - code = createBatch(&pBatch, pBatchList, pMsg); + code = createBatch(&pBatch, pBatchList, pReq); if (code != 0) { destroyBatchList(pBatchList); - destroyCmsg(pMsg); + destroyCmsg(pReq); continue; } @@ -2419,30 +2419,30 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { } else { if (QUEUE_IS_EMPTY(&(*ppBatchList)->wq)) { SCliBatch* pBatch = NULL; - code = createBatch(&pBatch, *ppBatchList, pMsg); + code = createBatch(&pBatch, *ppBatchList, pReq); if (code != 0) { - destroyCmsg(pMsg); + destroyCmsg(pReq); cliDestroyBatch(pBatch); } } else { queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); SCliBatch* pBatch = QUEUE_DATA(hdr, SCliBatch, listq); - if ((pBatch->batchSize + pMsg->msg.contLen) < (*ppBatchList)->batchLenLimit) { + if ((pBatch->batchSize + pReq->msg.contLen) < (*ppBatchList)->batchLenLimit) { QUEUE_PUSH(&pBatch->wq, h); - pBatch->batchSize += pMsg->msg.contLen; + pBatch->batchSize += pReq->msg.contLen; pBatch->wLen += 1; } else { SCliBatch* tBatch = NULL; - code = createBatch(&tBatch, *ppBatchList, pMsg); + code = createBatch(&tBatch, *ppBatchList, pReq); if (code != 0) { - destroyCmsg(pMsg); + destroyCmsg(pReq); } } } } continue; } - (*cliAsyncHandle[pMsg->type])(pMsg, pThrd); + (*cliAsyncHandle[pReq->type])(pReq, pThrd); count++; } @@ -2481,9 +2481,9 @@ void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { transCtxCleanup(&conn->ctx); cliReleaseUnfinishedMsg(conn); if (destroy == 1) { - transQueueDestroy(&conn->cliMsgs); + transQueueDestroy(&conn->reqMsgs); } else { - transQueueClear(&conn->cliMsgs); + transQueueClear(&conn->reqMsgs); } } @@ -2491,8 +2491,8 @@ void cliConnFreeMsgs(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) { - SCliMsg* cmsg = transQueueGet(&conn->cliMsgs, i); + for (int i = 0; i < transQueueSize(&conn->reqMsgs); i++) { + SCliReq* cmsg = transQueueGet(&conn->reqMsgs, i); if (cmsg->type == Release || REQUEST_NO_RESP(&cmsg->msg) || cmsg->msg.msgType == TDMT_SCH_DROP_TASK) { continue; } @@ -2507,7 +2507,7 @@ void cliConnFreeMsgs(SCliConn* conn) { bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { uint64_t ahandle = pHead->ahandle; - SCliMsg* pMsg = NULL; + SCliReq* pReq = NULL; CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); tDebug("%s conn %p receive release request, refId:%" PRId64 ", may ignore", CONN_GET_INST_LABEL(conn), conn, conn->refId); @@ -2515,10 +2515,10 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { (void)transClearBuffer(&conn->readBuf); transFreeMsg(transContFromHead((char*)pHead)); - for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->cliMsgs); i++) { - SCliMsg* cliMsg = transQueueGet(&conn->cliMsgs, i); + for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->reqMsgs); i++) { + SCliReq* cliMsg = transQueueGet(&conn->reqMsgs, i); if (cliMsg->type == Release) { - ASSERTS(pMsg == NULL, "trans-cli recv invaid release-req"); + ASSERTS(pReq == NULL, "trans-cli recv invaid release-req"); tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, conn->refId); cliDestroyConn(conn, true); @@ -2529,7 +2529,7 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { cliConnFreeMsgs(conn); tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, conn->refId); - destroyCmsg(pMsg); + destroyCmsg(pReq); addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); return true; @@ -2596,45 +2596,45 @@ _err: } static FORCE_INLINE void destroyCmsg(void* arg) { - SCliMsg* pMsg = arg; - if (pMsg == NULL) { + SCliReq* pReq = arg; + if (pReq == NULL) { return; } - tDebug("free memory:%p, free ctx: %p", pMsg, pMsg->ctx); + tDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); - transDestroyConnCtx(pMsg->ctx); - transFreeMsg(pMsg->msg.pCont); - taosMemoryFree(pMsg); + transDestroyConnCtx(pReq->ctx); + transFreeMsg(pReq->msg.pCont); + taosMemoryFree(pReq); } static FORCE_INLINE void destroyCmsgWrapper(void* arg, void* param) { if (arg == NULL) return; - SCliMsg* pMsg = arg; + SCliReq* pReq = arg; SCliThrd* pThrd = param; - if (pMsg->msg.info.notFreeAhandle == 0 && pThrd != NULL) { - if (pThrd->destroyAhandleFp) (*pThrd->destroyAhandleFp)(pMsg->msg.info.ahandle); + if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL) { + if (pThrd->destroyAhandleFp) (*pThrd->destroyAhandleFp)(pReq->msg.info.ahandle); } - destroyCmsg(pMsg); + destroyCmsg(pReq); } static FORCE_INLINE void destroyCmsgAndAhandle(void* param) { if (param == NULL) return; STaskArg* arg = param; - SCliMsg* pMsg = arg->param1; + SCliReq* pReq = arg->param1; SCliThrd* pThrd = arg->param2; - if (pMsg->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { - pThrd->destroyAhandleFp(pMsg->ctx->ahandle); + if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { + pThrd->destroyAhandleFp(pReq->ctx->ahandle); } - if (pMsg->msg.info.handle != 0) { - (void)transReleaseExHandle(transGetRefMgt(), (int64_t)pMsg->msg.info.handle); - (void)transRemoveExHandle(transGetRefMgt(), (int64_t)pMsg->msg.info.handle); + if (pReq->msg.info.handle != 0) { + (void)transReleaseExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); + (void)transRemoveExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); } - transDestroyConnCtx(pMsg->ctx); - transFreeMsg(pMsg->msg.pCont); - taosMemoryFree(pMsg); + transDestroyConnCtx(pReq->ctx); + transFreeMsg(pReq->msg.pCont); + taosMemoryFree(pReq); } static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { @@ -2757,7 +2757,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { (void)taosThreadJoin(pThrd->thread, NULL); CLI_RELEASE_UV(pThrd->loop); (void)taosThreadMutexDestroy(&pThrd->msgMtx); - TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliMsg, destroyCmsgWrapper, (void*)pThrd); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliReq, destroyCmsgWrapper, (void*)pThrd); transAsyncPoolDestroy(pThrd->asyncPool); transDQDestroy(pThrd->delayQueue, destroyCmsgAndAhandle); @@ -2803,7 +2803,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { taosMemoryFree(pThrd); } -static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx) { +static FORCE_INLINE void transDestroyConnCtx(SReqCtx* ctx) { // taosMemoryFree(ctx); } @@ -2811,7 +2811,7 @@ static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx) { int32_t cliSendQuit(SCliThrd* thrd) { // cli can stop gracefully int32_t code = 0; - SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* msg = taosMemoryCalloc(1, sizeof(SCliReq)); if (msg == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -2852,7 +2852,7 @@ FORCE_INLINE int cliRBChoseIdx(STrans* pInst) { } static FORCE_INLINE void doDelayTask(void* param) { STaskArg* arg = param; - cliHandleReq((SCliMsg*)arg->param1, (SCliThrd*)arg->param2); + cliHandleReq((SCliReq*)arg->param1, (SCliThrd*)arg->param2); taosMemoryFree(arg); } @@ -2864,30 +2864,41 @@ static FORCE_INLINE void doCloseIdleConn(void* param) { cliDestroyConn(conn, true); taosMemoryFree(arg); } -static FORCE_INLINE void cliPerfLog_schedMsg(SCliMsg* pMsg, char* label) { +static FORCE_INLINE void cliPerfLog_schedMsg(SCliReq* pReq, char* label) { if (!(rpcDebugFlag & DEBUG_DEBUG)) { return; } - STransConnCtx* pCtx = pMsg->ctx; - STraceId* trace = &pMsg->msg.info.traceId; - char tbuf[512] = {0}; + SReqCtx* pCtx = pReq->ctx; + STraceId* trace = &pReq->msg.info.traceId; + char tbuf[512] = {0}; (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; } +static FORCE_INLINE void cliPerfLog_epset(SCliConn* pConn, SCliReq* pReq) { + if (!(rpcDebugFlag & DEBUG_TRACE)) { + return; + } + SReqCtx* pCtx = pReq->ctx; -static FORCE_INLINE int32_t cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { - STrans* pInst = pThrd->pInst; - STransConnCtx* pCtx = pMsg->ctx; - cliPerfLog_schedMsg(pMsg, transLabel(pThrd->pInst)); + char tbuf[512] = {0}; + (void)epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + tTrace("%s conn %p extract epset from msg", CONN_GET_INST_LABEL(pConn), pConn); + return; +} + +static FORCE_INLINE int32_t cliSchedMsgToNextNode(SCliReq* pReq, SCliThrd* pThrd) { + STrans* pInst = pThrd->pInst; + SReqCtx* pCtx = pReq->ctx; + cliPerfLog_schedMsg(pReq, transLabel(pThrd->pInst)); STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); if (arg == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - arg->param1 = pMsg; + arg->param1 = pReq; arg->param2 = pThrd; SDelayTask* pTask = transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); @@ -2898,7 +2909,10 @@ static FORCE_INLINE int32_t cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd return 0; } -FORCE_INLINE bool cliTryExtractEpSet(STransMsg* pResp, SEpSet* dst) { +FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { + SReqCtx* ctx = pReq->ctx; + SEpSet* dst = &ctx->epSet; + if ((pResp == NULL || pResp->info.hasEpSet == 0)) { return false; } @@ -2920,10 +2934,12 @@ FORCE_INLINE bool cliTryExtractEpSet(STransMsg* pResp, SEpSet* dst) { pResp->pCont = buf; pResp->contLen = len; + pResp->info.hasEpSet = 1; + epsetAssign(dst, &epset); return true; } -bool cliResetEpset(STransConnCtx* pCtx, STransMsg* pResp, bool hasEpSet) { +bool cliResetEpset(SReqCtx* pCtx, STransMsg* pResp, bool hasEpSet) { bool noDelay = true; if (hasEpSet == false) { if (pResp->contLen == 0) { @@ -2989,16 +3005,8 @@ bool cliResetEpset(STransConnCtx* pCtx, STransMsg* pResp, bool hasEpSet) { return noDelay; } -int8_t cliRetryShouldRetry(STrans* pInst, STransMsg* pResp) { - bool retry = pInst->retry != NULL ? pInst->retry(pResp->code, pResp->msgType - 1) : false; - if (retry == false) { - return 0; - } - - return 1; -} -void cliRetryMayInitCtx(STrans* pInst, SCliMsg* pMsg) { - STransConnCtx* pCtx = pMsg->ctx; +void cliRetryMayInitCtx(STrans* pInst, SCliReq* pReq) { + SReqCtx* pCtx = pReq->ctx; if (!pCtx->retryInit) { pCtx->retryMinInterval = pInst->retryMinInterval; pCtx->retryMaxInterval = pInst->retryMaxInterval; @@ -3009,30 +3017,67 @@ void cliRetryMayInitCtx(STrans* pInst, SCliMsg* pMsg) { pCtx->retryStep = 0; pCtx->retryInit = true; pCtx->retryCode = TSDB_CODE_SUCCESS; - pMsg->msg.info.handle = 0; + pReq->msg.info.handle = 0; } } -int32_t cliRetryIsTimeout(STrans* pInst, SCliMsg* pMsg) { - STransConnCtx* pCtx = pMsg->ctx; + +int32_t cliRetryIsTimeout(STrans* pInst, SCliReq* pReq) { + SReqCtx* pCtx = pReq->ctx; if (pCtx->retryMaxTimeout != -1 && taosGetTimestampMs() - pCtx->retryInitTimestamp >= pCtx->retryMaxTimeout) { return 1; } return 0; } -bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { + +int8_t cliRetryShouldRetry(STrans* pInst, STransMsg* pResp) { + bool retry = pInst->retry != NULL ? pInst->retry(pResp->code, pResp->msgType - 1) : false; + if (retry == false) { + return 0; + } + + return 1; +} + +void cliRetryUpdate(SReqCtx* pCtx, int8_t noDelay) { + if (noDelay == false) { + pCtx->epsetRetryCnt = 1; + pCtx->retryStep++; + + int64_t factor = pow(pCtx->retryStepFactor, pCtx->retryStep - 1); + pCtx->retryNextInterval = factor * pCtx->retryMinInterval; + if (pCtx->retryNextInterval >= pCtx->retryMaxInterval) { + pCtx->retryNextInterval = pCtx->retryMaxInterval; + } + } else { + pCtx->retryNextInterval = 0; + pCtx->epsetRetryCnt++; + } +} + +int32_t cliRetryDoSched(SCliReq* pReq, SCliThrd* pThrd) { + pReq->sent = 0; + int32_t code = cliSchedMsgToNextNode(pReq, pThrd); + if (code != 0) { + tError("failed to sched msg to next node, reason:%s", tstrerror(code)); + return code; + } + return 0; +} + +bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - STransConnCtx* pCtx = pMsg->ctx; - int32_t code = pResp->code; + SReqCtx* pCtx = pReq->ctx; + int32_t code = pResp->code; - cliRetryMayInitCtx(pInst, pMsg); + cliRetryMayInitCtx(pInst, pReq); if (!cliRetryShouldRetry(pInst, pResp)) { return false; } - if (cliRetryIsTimeout(pInst, pMsg)) { + if (cliRetryIsTimeout(pInst, pReq)) { return false; } // code, msgType @@ -3071,22 +3116,11 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { pCtx->retryCode = code; } - if (noDelay == false) { - pCtx->epsetRetryCnt = 1; - pCtx->retryStep++; + cliRetryUpdate(pCtx, noDelay); - int64_t factor = pow(pCtx->retryStepFactor, pCtx->retryStep - 1); - pCtx->retryNextInterval = factor * pCtx->retryMinInterval; - if (pCtx->retryNextInterval >= pCtx->retryMaxInterval) { - pCtx->retryNextInterval = pCtx->retryMaxInterval; - } - } else { - pCtx->retryNextInterval = 0; - pCtx->epsetRetryCnt++; - } + pReq->sent = 0; - pMsg->sent = 0; - code = cliSchedMsgToNextNode(pMsg, pThrd); + code = cliRetryDoSched(pReq, pThrd); if (code != 0) { pResp->code = code; tError("failed to sched msg to next node, reason:%s", tstrerror(code)); @@ -3094,7 +3128,9 @@ bool cliGenRetryRule(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } return true; } -void cliMayReSetRespCode(STransConnCtx* pCtx, STransMsg* pResp) { + +void cliMayResetRespCode(SCliReq* pReq, STransMsg* pResp) { + SReqCtx* pCtx = pReq->ctx; if (pCtx->retryCode != TSDB_CODE_SUCCESS) { int32_t code = pResp->code; // return internal code app @@ -3113,33 +3149,13 @@ void cliMayReSetRespCode(STransConnCtx* pCtx, STransMsg* pResp) { } } } -int cliNotifyCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { + +int32_t cliNotifyImplCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - - if (pMsg == NULL || pMsg->ctx == NULL) { - tTrace("%s conn %p handle resp", pInst->label, pConn); - pInst->cfp(pInst->parent, pResp, NULL); - return 0; - } - - bool retry = cliGenRetryRule(pConn, pResp, pMsg); - if (retry == true) { - return -1; - } - - STransConnCtx* pCtx = pMsg->ctx; - cliMayReSetRespCode(pCtx, pResp); - + SReqCtx* pCtx = pReq->ctx; STraceId* trace = &pResp->info.traceId; - bool hasEpSet = cliTryExtractEpSet(pResp, &pCtx->epSet); - if (hasEpSet) { - if (rpcDebugFlag & DEBUG_TRACE) { - char tbuf[512] = {0}; - (void)epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); - tGTrace("%s conn %p extract epset from msg", CONN_GET_INST_LABEL(pConn), pConn); - } - } + if (pCtx->pSem || pCtx->syncMsgRef != 0) { tGTrace("%s conn %p(sync) handle resp", CONN_GET_INST_LABEL(pConn), pConn); if (pCtx->pSem) { @@ -3166,7 +3182,7 @@ int cliNotifyCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } } else { tGTrace("%s conn %p handle resp", CONN_GET_INST_LABEL(pConn), pConn); - if (retry == false && hasEpSet == true) { + if (pResp->info.hasEpSet == 1) { pInst->cfp(pInst->parent, pResp, &pCtx->epSet); } else { if (!cliIsEpsetUpdated(pResp->code, pCtx)) { @@ -3178,6 +3194,28 @@ int cliNotifyCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } return 0; } +int32_t cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + if (pReq == NULL || pReq->ctx == NULL) { + tTrace("%s conn %p handle resp", pInst->label, pConn); + pInst->cfp(pInst->parent, pResp, NULL); + return 0; + } + + bool retry = cliMayRetry(pConn, pReq, pResp); + if (retry == true) { + return -1; + } + + cliMayResetRespCode(pReq, pResp); + + if (cliTryUpdateEpset(pReq, pResp)) { + cliPerfLog_epset(pConn, pReq); + } + return cliNotifyImplCb(pConn, pReq, pResp); +} void transCloseClient(void* arg) { int32_t code = 0; @@ -3251,14 +3289,14 @@ int32_t transReleaseCliHandle(void* handle) { STransMsg tmsg = {.info.handle = handle, .info.ahandle = (void*)0x9527}; TRACE_SET_MSGID(&tmsg.info.traceId, tGenIdPI64()); - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } pCtx->ahandle = tmsg.info.ahandle; - SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* cmsg = taosMemoryCalloc(1, sizeof(SCliReq)); if (cmsg == NULL) { taosMemoryFree(pCtx); return TSDB_CODE_OUT_OF_MEMORY; @@ -3278,10 +3316,10 @@ int32_t transReleaseCliHandle(void* handle) { return code; } -static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx, SCliMsg** pCliMsg) { +static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx, SCliReq** pCliMsg) { TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -3294,7 +3332,7 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq if (ctx != NULL) pCtx->appCtx = *ctx; - SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* cliMsg = taosMemoryCalloc(1, sizeof(SCliReq)); if (cliMsg == NULL) { taosMemoryFree(pCtx); return TSDB_CODE_OUT_OF_MEMORY; @@ -3331,7 +3369,7 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S if (exh != NULL) { taosWLockLatch(&exh->latch); if (exh->handle == NULL && exh->inited != 0) { - SCliMsg* pCliMsg = NULL; + SCliReq* pCliMsg = NULL; code = transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg); if (code != 0) { taosWUnLockLatch(&exh->latch); @@ -3352,7 +3390,7 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S } } - SCliMsg* pCliMsg = NULL; + SCliReq* pCliMsg = NULL; TAOS_CHECK_GOTO(transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg), NULL, _exception); STraceId* trace = &pReq->info.traceId; @@ -3398,7 +3436,7 @@ int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* p pReq->info.handle = (void*)(*transpointId); - SCliMsg* pCliMsg = NULL; + SCliReq* pCliMsg = NULL; TAOS_CHECK_GOTO(transInitMsg(shandle, pEpSet, pReq, NULL, &pCliMsg), NULL, _exception); STraceId* trace = &pReq->info.traceId; @@ -3451,7 +3489,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { (void)tsem_destroy(sem); taosMemoryFree(sem); @@ -3465,7 +3503,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra pCtx->pSem = sem; pCtx->pRsp = pTransRsp; - SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* cliMsg = taosMemoryCalloc(1, sizeof(SCliReq)); if (cliMsg == NULL) { (void)tsem_destroy(sem); taosMemoryFree(sem); @@ -3563,7 +3601,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); } @@ -3585,7 +3623,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _RETURN2); } - SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* cliMsg = taosMemoryCalloc(1, sizeof(SCliReq)); if (cliMsg == NULL) { taosMemoryFree(pCtx); TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); @@ -3651,7 +3689,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { int32_t code = 0; for (int8_t i = 0; i < pInst->numOfThreads; i++) { - STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); + SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; break; @@ -3659,7 +3697,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { pCtx->cvtAddr = cvtAddr; - SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* cliMsg = taosMemoryCalloc(1, sizeof(SCliReq)); if (cliMsg == NULL) { taosMemoryFree(pCtx); code = TSDB_CODE_OUT_OF_MEMORY; @@ -3726,7 +3764,7 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); } - SCliMsg* pCli = taosMemoryCalloc(1, sizeof(SCliMsg)); + SCliReq* pCli = taosMemoryCalloc(1, sizeof(SCliReq)); if (pCli == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); } @@ -3752,7 +3790,7 @@ _exception: int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { SCliConn* args1 = container_of(a, SCliConn, node); SCliConn* args2 = container_of(b, SCliConn, node); - if (transQueueSize(&args1->cliMsgs) > transQueueSize(&args2->cliMsgs)) { + if (transQueueSize(&args1->reqMsgs) > transQueueSize(&args2->reqMsgs)) { return 0; } return 1; From cc0a3e3683592f6fb78c481f231cccb875d3c0bb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 23 Aug 2024 09:54:59 +0800 Subject: [PATCH 033/240] fix random_err crash --- source/libs/transport/src/transCli.c | 76 ++++++++++++++-------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 116904e9c7..537563664e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1285,7 +1285,7 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { transMsg.info.cliVer = pInst->compatibilityVer; transMsg.info.ahandle = pCtx->ahandle; - pReq->seqNum = 0; + pReq->seq = 0; code = cliNotifyCb(conn, pReq, &transMsg); if (code != 0) { continue; @@ -1372,7 +1372,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { totalLen += msgLen; pCliMsg->sent = 1; - pCliMsg->seqNum = pHead->seqNum; + pCliMsg->seq = pHead->seqNum; } uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); req->data = pConn; @@ -2516,8 +2516,8 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { transFreeMsg(transContFromHead((char*)pHead)); for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->reqMsgs); i++) { - SCliReq* cliMsg = transQueueGet(&conn->reqMsgs, i); - if (cliMsg->type == Release) { + SCliReq* pReq = transQueueGet(&conn->reqMsgs, i); + if (pReq->type == Release) { ASSERTS(pReq == NULL, "trans-cli recv invaid release-req"); tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, conn->refId); @@ -3332,20 +3332,20 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq if (ctx != NULL) pCtx->appCtx = *ctx; - SCliReq* cliMsg = taosMemoryCalloc(1, sizeof(SCliReq)); - if (cliMsg == NULL) { + SCliReq* pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); + if (pReq == 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); + pCliReq->ctx = pCtx; + pCliReq->msg = *pReq; + pCliReq->st = taosGetTimestampUs(); + pCliReq->type = Normal; + pCliReq->refId = (int64_t)shandle; + QUEUE_INIT(&pCliReq->seqq); - *pCliMsg = cliMsg; + *pCliMsg = pCliReq; return 0; } @@ -3503,27 +3503,27 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra pCtx->pSem = sem; pCtx->pRsp = pTransRsp; - SCliReq* cliMsg = taosMemoryCalloc(1, sizeof(SCliReq)); - if (cliMsg == NULL) { + SCliReq* pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); + if (pCliReq == 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(); - cliMsg->type = Normal; - cliMsg->refId = (int64_t)shandle; + pCliReq->ctx = pCtx; + pCliReq->msg = *pReq; + pCliReq->st = taosGetTimestampUs(); + pCliReq->type = Normal; + pCliReq->refId = (int64_t)shandle; STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); - code = transAsyncSend(pThrd->asyncPool, &cliMsg->q); + code = transAsyncSend(pThrd->asyncPool, &pCliReq->q); if (code != 0) { - destroyCmsg(cliMsg); + destroyCmsg(pReq); TAOS_CHECK_GOTO((code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code), NULL, _RETURN); } (void)tsem_wait(sem); @@ -3623,25 +3623,25 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _RETURN2); } - SCliReq* cliMsg = taosMemoryCalloc(1, sizeof(SCliReq)); - if (cliMsg == NULL) { + SCliReq* pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); + if (pReq == NULL) { taosMemoryFree(pCtx); TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2); } - cliMsg->ctx = pCtx; - cliMsg->msg = *pReq; - cliMsg->st = taosGetTimestampUs(); - cliMsg->type = Normal; - cliMsg->refId = (int64_t)shandle; + pCliReq->ctx = pCtx; + pCliReq->msg = *pReq; + pCliReq->st = taosGetTimestampUs(); + pCliReq->type = Normal; + pCliReq->refId = (int64_t)shandle; STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); - code = transAsyncSend(pThrd->asyncPool, &cliMsg->q); + code = transAsyncSend(pThrd->asyncPool, &pCliReq->q); if (code != 0) { - destroyCmsg(cliMsg); + destroyCmsg(pReq); TAOS_CHECK_GOTO(code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code, NULL, _RETURN); goto _RETURN; } @@ -3697,22 +3697,22 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { pCtx->cvtAddr = cvtAddr; - SCliReq* cliMsg = taosMemoryCalloc(1, sizeof(SCliReq)); - if (cliMsg == NULL) { + SCliReq* pReq = taosMemoryCalloc(1, sizeof(SCliReq)); + if (pReq == NULL) { taosMemoryFree(pCtx); code = TSDB_CODE_OUT_OF_MEMORY; break; } - cliMsg->ctx = pCtx; - cliMsg->type = Update; - cliMsg->refId = (int64_t)shandle; + pReq->ctx = pCtx; + pReq->type = Update; + pReq->refId = (int64_t)shandle; SCliThrd* thrd = ((SCliObj*)pInst->tcphandle)->pThreadObj[i]; tDebug("%s update epset at thread:%08" PRId64, pInst->label, thrd->pid); - if ((code = transAsyncSend(thrd->asyncPool, &(cliMsg->q))) != 0) { - destroyCmsg(cliMsg); + if ((code = transAsyncSend(thrd->asyncPool, &(pReq->q))) != 0) { + destroyCmsg(pReq); if (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT) { code = TSDB_CODE_RPC_MODULE_QUIT; } From a7d76aaaf2b1726837804895ed2e9d593181b66b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 23 Aug 2024 11:50:54 +0800 Subject: [PATCH 034/240] refactor transport --- source/libs/transport/inc/transComm.h | 20 +- source/libs/transport/inc/transportInt.h | 4 +- source/libs/transport/src/trans.c | 30 +- source/libs/transport/src/transCli.c | 525 +++++++++++------------ source/libs/transport/src/transSvr.c | 10 +- 5 files changed, 287 insertions(+), 302 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index f4d5fcfe16..b811d192bd 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -142,7 +142,7 @@ typedef struct { tmsg_t msgType; // message type int8_t connType; // connection type cli/srv - STransCtx appCtx; // + STransCtx userCtx; // STransMsg* pRsp; // for synchronous API tsem_t* pSem; // for synchronous API STransSyncMsg* pSyncMsg; // for syncchronous with timeout API @@ -318,24 +318,24 @@ void transUnrefCliHandle(void* handle); int32_t transReleaseCliHandle(void* handle); int32_t transReleaseSrvHandle(void* handle); -int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* pCtx); -int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp); -int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, +int32_t transSendRequest(void* pInit, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* pCtx); +int32_t transSendRecv(void* pInit, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp); +int32_t transSendRecvWithTimeout(void* pInit, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs); -int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId); -int32_t transFreeConnById(void* shandle, int64_t transpointId); +int32_t transSendRequestWithId(void* pInit, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId); +int32_t transFreeConnById(void* pInit, int64_t transpointId); int32_t transSendResponse(const STransMsg* msg); int32_t transRegisterMsg(const STransMsg* msg); -int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn); -int32_t transSetIpWhiteList(void* shandle, void* arg, FilteFunc* func); +int32_t transSetDefaultAddr(void* pInit, const char* ip, const char* fqdn); +int32_t transSetIpWhiteList(void* pInit, void* arg, FilteFunc* func); int32_t transSockInfo2Str(struct sockaddr* sockname, char* dst); int32_t transAllocHandle(int64_t* refId); -void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); -void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); +void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit); +void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit); void transCloseClient(void* arg); void transCloseServer(void* arg); diff --git a/source/libs/transport/inc/transportInt.h b/source/libs/transport/inc/transportInt.h index f56c435cba..8199ee21c9 100644 --- a/source/libs/transport/inc/transportInt.h +++ b/source/libs/transport/inc/transportInt.h @@ -32,8 +32,8 @@ extern "C" { #endif -void* taosInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); -void* taosInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); +void* taosInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit); +void* taosInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit); void taosCloseServer(void* arg); void taosCloseClient(void* arg); diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 6b0b557f1c..ff53d01ca0 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -15,7 +15,7 @@ #include "transComm.h" -void* (*taosInitHandle[])(uint32_t ip, uint32_t port, char* label, int32_t numOfThreads, void* fp, void* shandle) = { +void* (*taosInitHandle[])(uint32_t ip, uint32_t port, char* label, int32_t numOfThreads, void* fp, void* pInit) = { transInitServer, transInitClient}; void (*taosCloseHandle[])(void* arg) = {transCloseServer, transCloseClient}; @@ -103,7 +103,7 @@ void* rpcOpen(const SRpcInit* pInit) { pRpc->timeToGetConn = 10 * 1000; } pRpc->notWaitAvaliableConn = pInit->notWaitAvaliableConn; - + pRpc->tcphandle = (*taosInitHandle[pRpc->connType])(ip, pInit->localPort, pRpc->label, pRpc->numOfThreads, NULL, pRpc); @@ -167,29 +167,29 @@ void* rpcReallocCont(void* ptr, int64_t contLen) { return st + TRANS_MSG_OVERHEAD; } -int32_t rpcSendRequest(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid) { - return transSendRequest(shandle, pEpSet, pMsg, NULL); +int32_t rpcSendRequest(void* pInit, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid) { + return transSendRequest(pInit, pEpSet, pMsg, NULL); } -int32_t rpcSendRequestWithCtx(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid, SRpcCtx* pCtx) { - if (pCtx != NULL || pMsg->info.handle != 0 || pMsg->info.noResp != 0|| pRid == NULL) { - return transSendRequest(shandle, pEpSet, pMsg, pCtx); +int32_t rpcSendRequestWithCtx(void* pInit, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid, SRpcCtx* pCtx) { + if (pCtx != NULL || pMsg->info.handle != 0 || pMsg->info.noResp != 0 || pRid == NULL) { + return transSendRequest(pInit, pEpSet, pMsg, pCtx); } else { - return transSendRequestWithId(shandle, pEpSet, pMsg, pRid); + return transSendRequestWithId(pInit, pEpSet, pMsg, pRid); } } -int32_t rpcSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { - return transSendRequestWithId(shandle, pEpSet, pReq, transpointId); +int32_t rpcSendRequestWithId(void* pInit, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { + return transSendRequestWithId(pInit, pEpSet, pReq, transpointId); } -int32_t rpcSendRecv(void* shandle, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp) { - return transSendRecv(shandle, pEpSet, pMsg, pRsp); +int32_t rpcSendRecv(void* pInit, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp) { + return transSendRecv(pInit, pEpSet, pMsg, pRsp); } -int32_t rpcSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp, int8_t* epUpdated, +int32_t rpcSendRecvWithTimeout(void* pInit, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs) { - return transSendRecvWithTimeout(shandle, pEpSet, pMsg, pRsp, epUpdated, timeoutMs); + return transSendRecvWithTimeout(pInit, pEpSet, pMsg, pRsp, epUpdated, timeoutMs); } -int32_t rpcFreeConnById(void* shandle, int64_t connId) { return transFreeConnById(shandle, connId); } +int32_t rpcFreeConnById(void* pInit, int64_t connId) { return transFreeConnById(pInit, connId); } int32_t rpcSendResponse(const SRpcMsg* pMsg) { return transSendResponse(pMsg); } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 537563664e..5218d376ae 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -98,7 +98,7 @@ typedef struct SCliReq { queue q; STransMsgType type; - int64_t refId; + // int64_t refId; uint64_t st; int sent; //(0: no send, 1: alread sent) queue seqq; @@ -232,12 +232,12 @@ static void cliHandleFreeById(SCliReq* pReq, SCliThrd* pThrd); static void (*cliAsyncHandle[])(SCliReq* pReq, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL, cliHandleUpdate, cliHandleFreeById}; -static FORCE_INLINE void destroyCmsg(void* cmsg); +static FORCE_INLINE void destroyReq(void* cmsg); -static FORCE_INLINE void destroyCmsgWrapper(void* arg, void* param); -static FORCE_INLINE void destroyCmsgAndAhandle(void* cmsg); +static FORCE_INLINE void destroyReqWrapper(void* arg, void* param); +static FORCE_INLINE void destroyReqAndAhanlde(void* cmsg); static FORCE_INLINE int cliRBChoseIdx(STrans* pInst); -static FORCE_INLINE void transDestroyConnCtx(SReqCtx* ctx); +static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx); static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); @@ -361,7 +361,7 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { pThrd->destroyAhandleFp(msg->ctx->ahandle); } } - destroyCmsg(msg); + destroyReq(msg); } transQueueClear(&conn->reqMsgs); memset(&conn->ctx, 0, sizeof(conn->ctx)); @@ -393,7 +393,7 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { QUEUE_REMOVE(h); taosWUnLockLatch(&exh->latch); SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); - transCtxMerge(&conn->ctx, &t->ctx->appCtx); + transCtxMerge(&conn->ctx, &t->ctx->userCtx); (void)transQueuePush(&conn->reqMsgs, t); tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); (void)transReleaseExHandle(transGetRefMgt(), refId); @@ -483,10 +483,11 @@ void cliHandleResp_shareConn(SCliConn* conn) { if (ret != 0) { return; } else { - destroyCmsg(pReq); + destroyReq(pReq); } } void cliHandleResp(SCliConn* conn) { + int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; @@ -502,6 +503,7 @@ void cliHandleResp(SCliConn* conn) { if (msgLen <= 0) { taosMemoryFree(pHead); tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); + // TODO: notify cb return; } @@ -509,8 +511,9 @@ void cliHandleResp(SCliConn* conn) { tTrace("%s conn %p not reset read buf", transLabel(pInst), conn); } - if (transDecompressMsg((char**)&pHead, msgLen) < 0) { + if ((code = transDecompressMsg((char**)&pHead, msgLen)) < 0) { tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); + // TODO: notify cb } pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); @@ -584,7 +587,7 @@ void cliHandleResp(SCliConn* conn) { } int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); tDebug("conn %p msg refId: %" PRId64 "", conn, refId); - destroyCmsg(pReq); + destroyReq(pReq); if (cliConnSendSeqMsg(refId, conn)) { return; @@ -609,7 +612,7 @@ static void cliDestroyMsgInExhandle(int64_t refId) { queue* h = QUEUE_HEAD(&exh->q); QUEUE_REMOVE(h); SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); - destroyCmsg(t); + destroyReq(t); } taosWUnLockLatch(&exh->latch); (void)transReleaseExHandle(transGetRefMgt(), refId); @@ -636,7 +639,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { } if (pReq != NULL && REQUEST_NO_RESP(&pReq->msg)) { - destroyCmsg(pReq); + destroyReq(pReq); break; } @@ -666,7 +669,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { if (pCtx == NULL || pCtx->pSem == NULL) { if (transMsg.info.ahandle == NULL) { if (pReq == NULL || REQUEST_NO_RESP(&pReq->msg) || pReq->type == Release) { - destroyCmsg(pReq); + destroyReq(pReq); once = true; continue; } @@ -680,7 +683,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { return; } } - destroyCmsg(pReq); + destroyReq(pReq); tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); } while (!transQueueEmpty(&pConn->reqMsgs)); if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); @@ -937,7 +940,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { transDQCancel(thrd->waitConnQueue, pReq->ctx->task); pReq->ctx->task = NULL; - transCtxMerge(&conn->ctx, &pReq->ctx->appCtx); + transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); (void)transQueuePush(&conn->reqMsgs, pReq); conn->status = ConnNormal; @@ -1218,7 +1221,7 @@ static bool cliHandleNoResp(SCliConn* conn) { SCliReq* pReq = transQueueGet(&conn->reqMsgs, 0); if (REQUEST_NO_RESP(&pReq->msg)) { (void)transQueuePop(&conn->reqMsgs); - destroyCmsg(pReq); + destroyReq(pReq); res = true; } if (res == true) { @@ -1291,7 +1294,7 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { continue; } else { // already notify user - destroyCmsg(pReq); + destroyReq(pReq); } } @@ -1518,17 +1521,6 @@ void cliSend(SCliConn* pConn) { STraceId* trace = &pReq->info.traceId; - if (pInst->startTimer != NULL && pInst->startTimer(0, pReq->msgType)) { - 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)); - tDebug("no available timer, create a timer %p", timer); - (void)uv_timer_init(pThrd->loop, timer); - } - timer->data = pConn; - pConn->timer = timer; - } - if (pHead->comp == 0 && pReq->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { msgLen = transCompressMsg(pReq->pCont, pReq->contLen) + sizeof(STransMsgHead); @@ -1568,7 +1560,7 @@ static void cliDestroyBatch(SCliBatch* pBatch) { QUEUE_REMOVE(h); SCliReq* p = QUEUE_DATA(h, SCliReq, q); - destroyCmsg(p); + destroyReq(p); } SCliBatchList* p = pBatch->pList; p->sending -= 1; @@ -1810,7 +1802,7 @@ static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code) { pInst->cfp(pInst->parent, &transMsg, NULL); } - destroyCmsg(pReq); + destroyReq(pReq); } static void cliHandleQuit(SCliReq* pReq, SCliThrd* pThrd) { if (!transAsyncPoolIsEmpty(pThrd->asyncPool)) { @@ -1820,7 +1812,7 @@ static void cliHandleQuit(SCliReq* pReq, SCliThrd* pThrd) { pThrd->stopMsg = NULL; pThrd->quit = true; tDebug("cli work thread %p start to quit", pThrd); - destroyCmsg(pReq); + destroyReq(pReq); (void)destroyConnPool(pThrd); (void)uv_walk(pThrd->loop, cliWalkCb, NULL); @@ -1830,7 +1822,7 @@ static void cliHandleRelease(SCliReq* pReq, SCliThrd* pThrd) { SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); if (exh == NULL) { tDebug("%" PRId64 " already released", refId); - destroyCmsg(pReq); + destroyReq(pReq); return; } @@ -1849,13 +1841,13 @@ static void cliHandleRelease(SCliReq* pReq, SCliThrd* pThrd) { cliSend(conn); } else { tError("%s conn %p already released", CONN_GET_INST_LABEL(conn), conn); - destroyCmsg(pReq); + destroyReq(pReq); } } static void cliHandleUpdate(SCliReq* pReq, SCliThrd* pThrd) { SReqCtx* pCtx = pReq->ctx; pThrd->cvtAddr = pCtx->cvtAddr; - destroyCmsg(pReq); + destroyReq(pReq); } static void cliHandleFreeById(SCliReq* pReq, SCliThrd* pThrd) { int32_t code = 0; @@ -1863,7 +1855,7 @@ static void cliHandleFreeById(SCliReq* pReq, SCliThrd* pThrd) { SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); if (exh == NULL) { tDebug("id %" PRId64 " already released", refId); - destroyCmsg(pReq); + destroyReq(pReq); return; } @@ -1892,7 +1884,7 @@ _exception: (void)transReleaseExHandle(transGetRefMgt(), refId); (void)transReleaseExHandle(transGetRefMgt(), refId); (void)transRemoveExHandle(transGetRefMgt(), refId); - destroyCmsg(pReq); + destroyReq(pReq); } SCliConn* cliGetConn(SCliReq** pReq, SCliThrd* pThrd, bool* ignore, char* addr) { @@ -2116,158 +2108,158 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { } void cliHandleReq__shareConn(SCliReq* pReq, SCliThrd* pThrd) { - int32_t code = 0; + // int32_t code = 0; - STraceId* trace = &pReq->msg.info.traceId; - STrans* pInst = pThrd->pInst; + // STraceId* trace = &pReq->msg.info.traceId; + // STrans* pInst = pThrd->pInst; - code = cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); - if (code != 0) { - // notifyCb - destroyCmsg(pReq); - return; - } + // code = cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); + // if (code != 0) { + // // TODO: notifyCb + // destroyReq(pReq); + // return; + // } - char addr[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + // char addr[TSDB_FQDN_LEN + 64] = {0}; + // CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); - SCliConn* pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); - if (pConn == NULL) { - tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); - bool ignore = false; - pConn = getConnFromPool(pThrd, addr, &ignore); - if (pConn != NULL) { - addConnToHeapCache(pThrd->connHeapCache, pConn); - transQueuePush(&pConn->reqMsgs, pReq); - return cliSendBatch_shareConn(pConn); - } - } else { - tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); - transQueuePush(&pConn->reqMsgs, pReq); - cliSendBatch_shareConn(pConn); - return; - } + // SCliConn* pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); + // if (pConn == NULL) { + // tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); + // bool ignore = false; + // pConn = getConnFromPool(pThrd, addr, &ignore); + // if (pConn != NULL) { + // addConnToHeapCache(pThrd->connHeapCache, pConn); + // transQueuePush(&pConn->reqMsgs, pReq); + // return cliSendBatch_shareConn(pConn); + // } + // } else { + // tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); + // transQueuePush(&pConn->reqMsgs, pReq); + // cliSendBatch_shareConn(pConn); + // return; + // } - code = cliCreateConn(pThrd, &pConn); - pConn->dstAddr = taosStrdup(addr); - code = addConnToHeapCache(pThrd->connHeapCache, pConn); + // code = cliCreateConn(pThrd, &pConn); + // pConn->dstAddr = taosStrdup(addr); + // code = addConnToHeapCache(pThrd->connHeapCache, pConn); - transQueuePush(&pConn->reqMsgs, pReq); - return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + // transQueuePush(&pConn->reqMsgs, pReq); + // return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); } void cliHandleReq__noShareConn(SCliReq* pReq, SCliThrd* pThrd) { - int32_t code; - STrans* pInst = pThrd->pInst; - code = cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); - if (code != 0) { - // notifyCb - destroyCmsg(pReq); - } + // int32_t code; + // STrans* pInst = pThrd->pInst; + // code = cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); + // if (code != 0) { + // // notifyCb + // destroyReq(pReq); + // } - char* fqdn = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); - uint16_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); - char addr[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(addr, fqdn, port); + // char* fqdn = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); + // uint16_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); + // char addr[TSDB_FQDN_LEN + 64] = {0}; + // CONN_CONSTRUCT_HASH_KEY(addr, fqdn, port); - bool ignore = false; - SCliConn* conn = cliGetConn(&pReq, pThrd, &ignore, addr); - if (ignore == true) { - // persist conn already release by server - STransMsg resp = {0}; - if (pReq->type != Release) { - (void)cliBuildExceptRespAndNotifyCb(pThrd, pReq, 0); - } - destroyCmsg(pReq); - return; - } - if (conn == NULL && pReq == NULL) { - return; - } - STraceId* trace = &pReq->msg.info.traceId; + // bool ignore = false; + // SCliConn* conn = cliGetConn(&pReq, pThrd, &ignore, addr); + // if (ignore == true) { + // // persist conn already release by server + // STransMsg resp = {0}; + // if (pReq->type != Release) { + // (void)cliBuildExceptRespAndNotifyCb(pThrd, pReq, 0); + // } + // destroyReq(pReq); + // return; + // } + // if (conn == NULL && pReq == NULL) { + // return; + // } + // STraceId* trace = &pReq->msg.info.traceId; - if (conn != NULL) { - transCtxMerge(&conn->ctx, &pReq->ctx->appCtx); - (void)transQueuePush(&conn->reqMsgs, pReq); - cliSend(conn); - } else { - code = cliCreateConn(pThrd, &conn); - if (code != 0) { - tError("%s failed to create conn, reason:%s", pInst->label, tstrerror(code)); - (void)cliBuildExceptRespAndNotifyCb(pThrd, pReq, code); - destroyCmsg(pReq); - return; - } + // if (conn != NULL) { + // transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); + // (void)transQueuePush(&conn->reqMsgs, pReq); + // cliSend(conn); + // } else { + // code = cliCreateConn(pThrd, &conn); + // if (code != 0) { + // tError("%s failed to create conn, reason:%s", pInst->label, tstrerror(code)); + // (void)cliBuildExceptRespAndNotifyCb(pThrd, pReq, code); + // destroyReq(pReq); + // return; + // } - specifyConnRef(conn, true, (int64_t)pReq->msg.info.handle); + // specifyConnRef(conn, true, (int64_t)pReq->msg.info.handle); - transCtxMerge(&conn->ctx, &pReq->ctx->appCtx); - (void)transQueuePush(&conn->reqMsgs, pReq); + // transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); + // (void)transQueuePush(&conn->reqMsgs, pReq); - conn->dstAddr = taosStrdup(addr); - if (conn->dstAddr == NULL) { - tError("%s conn %p failed to send batch msg, reason:%s", transLabel(pInst), conn, - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - cliHandleFastFail(conn, -1); - return; - } + // conn->dstAddr = taosStrdup(addr); + // if (conn->dstAddr == NULL) { + // tError("%s conn %p failed to send batch msg, reason:%s", transLabel(pInst), conn, + // tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + // cliHandleFastFail(conn, -1); + // return; + // } - uint32_t ipaddr; - int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn, &ipaddr); - if (code != 0) { - cliResetConnTimer(conn); - cliHandleExcept(conn, code); - return; - } + // uint32_t ipaddr; + // int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn, &ipaddr); + // if (code != 0) { + // cliResetConnTimer(conn); + // cliHandleExcept(conn, code); + // return; + // } - struct sockaddr_in addr; - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = ipaddr; - addr.sin_port = (uint16_t)htons(port); + // struct sockaddr_in addr; + // addr.sin_family = AF_INET; + // addr.sin_addr.s_addr = ipaddr; + // addr.sin_port = (uint16_t)htons(port); - tGTrace("%s conn %p try to connect to %s", pInst->label, conn, conn->dstAddr); - int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); - if (fd == -1) { - tGError("%s conn %p failed to create socket, reason:%s", transLabel(pInst), conn, - tstrerror(TAOS_SYSTEM_ERROR(errno))); - cliHandleExcept(conn, -1); - errno = 0; - return; - } + // tGTrace("%s conn %p try to connect to %s", pInst->label, conn, conn->dstAddr); + // int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); + // if (fd == -1) { + // tGError("%s conn %p failed to create socket, reason:%s", transLabel(pInst), conn, + // tstrerror(TAOS_SYSTEM_ERROR(errno))); + // cliHandleExcept(conn, -1); + // 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(pInst), conn, uv_err_name(ret)); - cliHandleExcept(conn, -1); - 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(pInst), 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(pInst), 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(pInst), conn, uv_err_name(ret)); + // cliHandleExcept(conn, -1); + // return; + // } - ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); - if (ret != 0) { - cliResetConnTimer(conn); - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, ret); - return; - } - (void)uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); - } - tGTrace("%s conn %p ready", pInst->label, conn); + // ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); + // if (ret != 0) { + // cliResetConnTimer(conn); + // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); + // cliHandleFastFail(conn, ret); + // return; + // } + // (void)uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + // } + // tGTrace("%s conn %p ready", pInst->label, conn); } void cliHandleReq(SCliReq* pReq, SCliThrd* pThrd) { - STrans* pInst = pThrd->pInst; - if (pInst->shareConn == 1) { - return cliHandleReq__shareConn(pReq, pThrd); - } else { - return cliHandleReq__noShareConn(pReq, pThrd); - } + // STrans* pInst = pThrd->pInst; + // if (pInst->shareConn == 1) { + // return cliHandleReq__shareConn(pReq, pThrd); + // } else { + // return cliHandleReq__noShareConn(pReq, pThrd); + // } } static void cliDealReq(queue* wq, SCliThrd* pThrd) { @@ -2398,7 +2390,7 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { SCliBatchList* pBatchList = NULL; code = createBatchList(&pBatchList, key, ip, port); if (code != 0) { - destroyCmsg(pReq); + destroyReq(pReq); continue; } @@ -2408,7 +2400,7 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { code = createBatch(&pBatch, pBatchList, pReq); if (code != 0) { destroyBatchList(pBatchList); - destroyCmsg(pReq); + destroyReq(pReq); continue; } @@ -2421,7 +2413,7 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { SCliBatch* pBatch = NULL; code = createBatch(&pBatch, *ppBatchList, pReq); if (code != 0) { - destroyCmsg(pReq); + destroyReq(pReq); cliDestroyBatch(pBatch); } } else { @@ -2435,7 +2427,7 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { SCliBatch* tBatch = NULL; code = createBatch(&tBatch, *ppBatchList, pReq); if (code != 0) { - destroyCmsg(pReq); + destroyReq(pReq); } } } @@ -2529,7 +2521,7 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { cliConnFreeMsgs(conn); tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, conn->refId); - destroyCmsg(pReq); + destroyReq(pReq); addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); return true; @@ -2537,6 +2529,48 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { return false; } +static FORCE_INLINE void destroyReq(void* arg) { + SCliReq* pReq = arg; + if (pReq == NULL) { + return; + } + tDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); + + destroyReqCtx(pReq->ctx); + transFreeMsg(pReq->msg.pCont); + taosMemoryFree(pReq); +} +static FORCE_INLINE void destroyReqWrapper(void* arg, void* param) { + if (arg == NULL) return; + + SCliReq* pReq = arg; + SCliThrd* pThrd = param; + if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL) { + if (pThrd->destroyAhandleFp) (*pThrd->destroyAhandleFp)(pReq->msg.info.ahandle); + } + destroyReq(pReq); +} +static FORCE_INLINE void destroyReqAndAhanlde(void* param) { + if (param == NULL) return; + + STaskArg* arg = param; + SCliReq* pReq = arg->param1; + SCliThrd* pThrd = arg->param2; + + if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { + pThrd->destroyAhandleFp(pReq->ctx->ahandle); + } + + if (pReq->msg.info.handle != 0) { + (void)transReleaseExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); + (void)transRemoveExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); + } + + destroyReqCtx(pReq->ctx); + transFreeMsg(pReq->msg.pCont); + taosMemoryFree(pReq); +} + static void* cliWorkThread(void* arg) { char threadName[TSDB_LABEL_LEN] = {0}; @@ -2552,14 +2586,14 @@ static void* cliWorkThread(void* arg) { return NULL; } -void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) { +void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInstRef) { int32_t code = 0; SCliObj* cli = taosMemoryCalloc(1, sizeof(SCliObj)); if (cli == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _err); } - STrans* pInst = shandle; + STrans* pInst = pInstRef; memcpy(cli->label, label, TSDB_LABEL_LEN); cli->numOfThreads = numOfThreads; @@ -2570,7 +2604,7 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, for (int i = 0; i < cli->numOfThreads; i++) { SCliThrd* pThrd = NULL; - code = createThrdObj(shandle, &pThrd); + code = createThrdObj(pInstRef, &pThrd); if (code != 0) { goto _err; } @@ -2595,48 +2629,6 @@ _err: return NULL; } -static FORCE_INLINE void destroyCmsg(void* arg) { - SCliReq* pReq = arg; - if (pReq == NULL) { - return; - } - tDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); - - transDestroyConnCtx(pReq->ctx); - transFreeMsg(pReq->msg.pCont); - taosMemoryFree(pReq); -} -static FORCE_INLINE void destroyCmsgWrapper(void* arg, void* param) { - if (arg == NULL) return; - - SCliReq* pReq = arg; - SCliThrd* pThrd = param; - if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL) { - if (pThrd->destroyAhandleFp) (*pThrd->destroyAhandleFp)(pReq->msg.info.ahandle); - } - destroyCmsg(pReq); -} -static FORCE_INLINE void destroyCmsgAndAhandle(void* param) { - if (param == NULL) return; - - STaskArg* arg = param; - SCliReq* pReq = arg->param1; - SCliThrd* pThrd = arg->param2; - - if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { - pThrd->destroyAhandleFp(pReq->ctx->ahandle); - } - - if (pReq->msg.info.handle != 0) { - (void)transReleaseExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); - (void)transRemoveExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); - } - - transDestroyConnCtx(pReq->ctx); - transFreeMsg(pReq->msg.pCont); - taosMemoryFree(pReq); -} - static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { int32_t code = 0; STrans* pInst = trans; @@ -2757,10 +2749,10 @@ static void destroyThrdObj(SCliThrd* pThrd) { (void)taosThreadJoin(pThrd->thread, NULL); CLI_RELEASE_UV(pThrd->loop); (void)taosThreadMutexDestroy(&pThrd->msgMtx); - TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliReq, destroyCmsgWrapper, (void*)pThrd); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliReq, destroyReqWrapper, (void*)pThrd); transAsyncPoolDestroy(pThrd->asyncPool); - transDQDestroy(pThrd->delayQueue, destroyCmsgAndAhandle); + transDQDestroy(pThrd->delayQueue, destroyReqAndAhanlde); transDQDestroy(pThrd->timeoutQueue, NULL); transDQDestroy(pThrd->waitConnQueue, NULL); @@ -2803,10 +2795,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { taosMemoryFree(pThrd); } -static FORCE_INLINE void transDestroyConnCtx(SReqCtx* ctx) { - // - taosMemoryFree(ctx); -} +static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx) { taosMemoryFree(ctx); } int32_t cliSendQuit(SCliThrd* thrd) { // cli can stop gracefully @@ -2910,6 +2899,7 @@ static FORCE_INLINE int32_t cliSchedMsgToNextNode(SCliReq* pReq, SCliThrd* pThrd } FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { + int32_t code = 0; SReqCtx* ctx = pReq->ctx; SEpSet* dst = &ctx->epSet; @@ -2918,7 +2908,8 @@ FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { } // rebuild resp msg SEpSet epset; - if (tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epset) < 0) { + if ((code = tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epset)) < 0) { + tError("failed to deserialize epset, code:%d", code); return false; } int32_t tlen = tSerializeSEpSet(NULL, 0, dst); @@ -2927,6 +2918,7 @@ FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { int32_t len = pResp->contLen - tlen; if (len != 0) { buf = rpcMallocCont(len); + // TODO: check buf memcpy(buf, (char*)pResp->pCont + tlen, len); } rpcFreeCont(pResp->pCont); @@ -3031,14 +3023,10 @@ int32_t cliRetryIsTimeout(STrans* pInst, SCliReq* pReq) { int8_t cliRetryShouldRetry(STrans* pInst, STransMsg* pResp) { bool retry = pInst->retry != NULL ? pInst->retry(pResp->code, pResp->msgType - 1) : false; - if (retry == false) { - return 0; - } - - return 1; + return retry == false ? 0 : 1; } -void cliRetryUpdate(SReqCtx* pCtx, int8_t noDelay) { +void cliRetryUpdateRule(SReqCtx* pCtx, int8_t noDelay) { if (noDelay == false) { pCtx->epsetRetryCnt = 1; pCtx->retryStep++; @@ -3055,7 +3043,6 @@ void cliRetryUpdate(SReqCtx* pCtx, int8_t noDelay) { } int32_t cliRetryDoSched(SCliReq* pReq, SCliThrd* pThrd) { - pReq->sent = 0; int32_t code = cliSchedMsgToNextNode(pReq, pThrd); if (code != 0) { tError("failed to sched msg to next node, reason:%s", tstrerror(code)); @@ -3080,8 +3067,8 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { if (cliRetryIsTimeout(pInst, pReq)) { return false; } - // code, msgType + // code, msgType // A: epset,leader, not self // B: epset,not know leader // C: noepset,leader but not serivce @@ -3116,7 +3103,7 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { pCtx->retryCode = code; } - cliRetryUpdate(pCtx, noDelay); + cliRetryUpdateRule(pCtx, noDelay); pReq->sent = 0; @@ -3310,13 +3297,13 @@ int32_t transReleaseCliHandle(void* handle) { tGDebug("send release request at thread:%08" PRId64 ", malloc memory:%p", pThrd->pid, cmsg); if ((code = transAsyncSend(pThrd->asyncPool, &cmsg->q)) != 0) { - destroyCmsg(cmsg); + destroyReq(cmsg); return code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code; } return code; } -static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx, SCliReq** pCliMsg) { +static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx, SCliReq** pCliMsg) { TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); @@ -3330,7 +3317,7 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; - if (ctx != NULL) pCtx->appCtx = *ctx; + if (ctx != NULL) pCtx->userCtx = *ctx; SCliReq* pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); if (pReq == NULL) { @@ -3342,7 +3329,6 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq pCliReq->msg = *pReq; pCliReq->st = taosGetTimestampUs(); pCliReq->type = Normal; - pCliReq->refId = (int64_t)shandle; QUEUE_INIT(&pCliReq->seqq); *pCliMsg = pCliReq; @@ -3350,8 +3336,8 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq return 0; } -int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) { - STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); +int32_t transSendRequest(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) { + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); if (pInst == NULL) { transFreeMsg(pReq->pCont); pReq->pCont = NULL; @@ -3370,7 +3356,7 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S taosWLockLatch(&exh->latch); if (exh->handle == NULL && exh->inited != 0) { SCliReq* pCliMsg = NULL; - code = transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg); + code = transInitMsg(pInstRef, pEpSet, pReq, ctx, &pCliMsg); if (code != 0) { taosWUnLockLatch(&exh->latch); (void)transReleaseExHandle(transGetRefMgt(), handle); @@ -3380,7 +3366,7 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S QUEUE_PUSH(&exh->q, &pCliMsg->seqq); taosWUnLockLatch(&exh->latch); tDebug("msg refId: %" PRId64 "", handle); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; } else { exh->inited = 1; @@ -3391,33 +3377,33 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S } SCliReq* pCliMsg = NULL; - TAOS_CHECK_GOTO(transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg), NULL, _exception); + TAOS_CHECK_GOTO(transInitMsg(pInstRef, pEpSet, pReq, ctx, &pCliMsg), NULL, _exception); STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { - destroyCmsg(pCliMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + destroyReq(pCliMsg); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } -int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { +int32_t transSendRequestWithId(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { if (transpointId == NULL) { ASSERT(0); return TSDB_CODE_INVALID_PARA; } int32_t code = 0; - STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); if (pInst == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_RPC_MODULE_QUIT, NULL, _exception); } @@ -3437,28 +3423,28 @@ int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* p pReq->info.handle = (void*)(*transpointId); SCliReq* pCliMsg = NULL; - TAOS_CHECK_GOTO(transInitMsg(shandle, pEpSet, pReq, NULL, &pCliMsg), NULL, _exception); + TAOS_CHECK_GOTO(transInitMsg(pInstRef, pEpSet, pReq, NULL, &pCliMsg), NULL, _exception); STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { - destroyCmsg(pCliMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + destroyReq(pCliMsg); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } -int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp) { - STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); +int32_t transSendRecv(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp) { + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); if (pInst == NULL) { transFreeMsg(pReq->pCont); pReq->pCont = NULL; @@ -3515,7 +3501,6 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra pCliReq->msg = *pReq; pCliReq->st = taosGetTimestampUs(); pCliReq->type = Normal; - pCliReq->refId = (int64_t)shandle; STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, @@ -3523,7 +3508,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra code = transAsyncSend(pThrd->asyncPool, &pCliReq->q); if (code != 0) { - destroyCmsg(pReq); + destroyReq(pReq); TAOS_CHECK_GOTO((code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code), NULL, _RETURN); } (void)tsem_wait(sem); @@ -3533,11 +3518,11 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra _RETURN: tsem_destroy(sem); taosMemoryFree(sem); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); taosMemoryFree(pTransRsp); return code; _RETURN1: - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); taosMemoryFree(pTransRsp); taosMemoryFree(pReq->pCont); pReq->pCont = NULL; @@ -3579,10 +3564,10 @@ _EXIT: taosMemoryFree(pSyncMsg); return code; } -int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, +int32_t transSendRecvWithTimeout(void* pInstRef, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs) { int32_t code = 0; - STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); if (pInst == NULL) { transFreeMsg(pReq->pCont); pReq->pCont = NULL; @@ -3633,7 +3618,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, pCliReq->msg = *pReq; pCliReq->st = taosGetTimestampUs(); pCliReq->type = Normal; - pCliReq->refId = (int64_t)shandle; + // pCliReq->refId = (int64_t)pInstRef; STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, @@ -3641,7 +3626,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, code = transAsyncSend(pThrd->asyncPool, &pCliReq->q); if (code != 0) { - destroyCmsg(pReq); + destroyReq(pReq); TAOS_CHECK_GOTO(code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code, NULL, _RETURN); goto _RETURN; } @@ -3660,7 +3645,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, code = 0; } _RETURN: - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); (void)taosReleaseRef(transGetSyncMsgMgt(), ref); (void)taosRemoveRef(transGetSyncMsgMgt(), ref); return code; @@ -3668,16 +3653,16 @@ _RETURN2: transFreeMsg(pReq->pCont); pReq->pCont = NULL; taosMemoryFree(pTransMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } /* * **/ -int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { +int32_t transSetDefaultAddr(void* pInstRef, const char* ip, const char* fqdn) { if (ip == NULL || fqdn == NULL) return TSDB_CODE_INVALID_PARA; - STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); if (pInst == NULL) { return TSDB_CODE_RPC_MODULE_QUIT; } @@ -3706,13 +3691,13 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { pReq->ctx = pCtx; pReq->type = Update; - pReq->refId = (int64_t)shandle; + // pReq->refId = (int64_t)pInstRef; SCliThrd* thrd = ((SCliObj*)pInst->tcphandle)->pThreadObj[i]; tDebug("%s update epset at thread:%08" PRId64, pInst->label, thrd->pid); if ((code = transAsyncSend(thrd->asyncPool, &(pReq->q))) != 0) { - destroyCmsg(pReq); + destroyReq(pReq); if (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT) { code = TSDB_CODE_RPC_MODULE_QUIT; } @@ -3720,7 +3705,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { } } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } @@ -3748,9 +3733,9 @@ int32_t transAllocHandle(int64_t* refId) { *refId = exh->refId; return 0; } -int32_t transFreeConnById(void* shandle, int64_t transpointId) { +int32_t transFreeConnById(void* pInstRef, int64_t transpointId) { int32_t code = 0; - STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); + STrans* pInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)pInstRef); if (pInst == NULL) { return TSDB_CODE_RPC_MODULE_QUIT; } @@ -3782,7 +3767,7 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) { } _exception: - transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 9c942c6d00..8acbe9f273 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1399,7 +1399,7 @@ static void uvPipeListenCb(uv_stream_t* handle, int status) { srv->numOfWorkerReady++; } -void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) { +void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* pInit) { int32_t code = 0; SServerObj* srv = taosMemoryCalloc(1, sizeof(SServerObj)); @@ -1463,9 +1463,9 @@ 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)); - thrd->pInst = shandle; + thrd->pInst = pInit; thrd->quit = false; - thrd->pInst = shandle; + thrd->pInst = pInit; thrd->pWhiteList = uvWhiteListCreate(); srv->pThreadObj[i] = thrd; @@ -1494,9 +1494,9 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, goto End; } - thrd->pInst = shandle; + thrd->pInst = pInit; thrd->quit = false; - thrd->pInst = shandle; + thrd->pInst = pInit; thrd->pWhiteList = uvWhiteListCreate(); if (thrd->pWhiteList == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; From a78a8c12302d04bbc37401e668c500e224a81ad5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 24 Aug 2024 18:03:50 +0800 Subject: [PATCH 035/240] refactor transport --- include/util/taoserror.h | 3 +- source/libs/transport/src/transCli.c | 762 ++++++++++++++------------ source/libs/transport/src/transComm.c | 4 - source/util/src/terror.c | 1 + 4 files changed, 406 insertions(+), 364 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index b772edbf22..a084f7b2f5 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -91,7 +91,8 @@ int32_t taosGetErrSize(); #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) +#define TSDB_CODE_RPC_ASYNC_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0027) +#define TSDB_CODE_RPC_ASYNC_IN_PROCESS TAOS_DEF_ERROR_CODE(0, 0x0028) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 5218d376ae..12022f495f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -65,7 +65,7 @@ typedef struct SCliConn { void* hostThrd; SConnBuffer readBuf; - STransQueue reqMsgs; + STransQueue reqs; queue q; SConnList* list; @@ -133,6 +133,10 @@ typedef struct SCliThrd { SCliReq* stopMsg; bool quit; + + int32_t (*initCb)(void* arg, SCliReq* pReq, STransMsg* pResp); + int32_t (*notifyCb)(void* arg, SCliReq* pReq, STransMsg* pResp); + int32_t (*notifyExceptCb)(void* arg, SCliReq* pReq, STransMsg* pResp); } SCliThrd; typedef struct SCliObj { @@ -157,6 +161,9 @@ static void* destroyConnPool(SCliThrd* thread); static SCliConn* getConnFromPool(SCliThrd* thread, char* key, bool* exceed); static void addConnToPool(void* pool, SCliConn* conn); static void doCloseIdleConn(void* param); +static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); +static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn); +static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port); // register conn timer static void cliConnTimeout(uv_timer_t* handle); @@ -219,17 +226,17 @@ static void cliHandleFastFail(SCliConn* pConn, int status); static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code); // handle req from app -static void cliHandleReq(SCliReq* pReq, SCliThrd* pThrd); -static void cliHandleQuit(SCliReq* pReq, SCliThrd* pThrd); -static void cliHandleRelease(SCliReq* pReq, SCliThrd* pThrd); -static void cliHandleUpdate(SCliReq* pReq, SCliThrd* pThrd); +static void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleFreeById(SCliThrd* pThrd, SCliReq* pReq); static void cliDealReq(queue* h, SCliThrd* pThrd); static void cliBatchDealReq(queue* h, SCliThrd* pThrd); static void (*cliDealFunc[])(queue* h, SCliThrd* pThrd) = {cliDealReq, cliBatchDealReq}; -static void cliHandleFreeById(SCliReq* pReq, SCliThrd* pThrd); -static void (*cliAsyncHandle[])(SCliReq* pReq, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, +static void (*cliAsyncHandle[])(SCliThrd* pThrd, SCliReq* pReq) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL, cliHandleUpdate, cliHandleFreeById}; static FORCE_INLINE void destroyReq(void* cmsg); @@ -289,9 +296,9 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); #define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ do { \ - int i = 0, sz = transQueueSize(&conn->reqMsgs); \ + int i = 0, sz = transQueueSize(&conn->reqs); \ for (; i < sz; i++) { \ - pReq = transQueueGet(&conn->reqMsgs, i); \ + pReq = transQueueGet(&conn->reqs, i); \ if (pReq->ctx != NULL && (uint64_t)pReq->ctx->ahandle == ahandle) { \ break; \ } \ @@ -299,22 +306,22 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); if (i == sz) { \ pReq = NULL; \ } else { \ - pReq = transQueueRm(&conn->reqMsgs, i); \ + pReq = transQueueRm(&conn->reqs, i); \ } \ } while (0) -#define CONN_GET_NEXT_SENDMSG(conn) \ - do { \ - int i = 0; \ - do { \ - pCliMsg = transQueueGet(&conn->reqMsgs, i++); \ - if (pCliMsg && 0 == pCliMsg->sent) { \ - break; \ - } \ - } while (pCliMsg != NULL); \ - if (pCliMsg == NULL) { \ - goto _RETURN; \ - } \ +#define CONN_GET_NEXT_SENDMSG(conn) \ + do { \ + int i = 0; \ + do { \ + pCliMsg = transQueueGet(&conn->reqs, i++); \ + if (pCliMsg && 0 == pCliMsg->sent) { \ + break; \ + } \ + } while (pCliMsg != NULL); \ + if (pCliMsg == NULL) { \ + goto _RETURN; \ + } \ } while (0) #define CONN_SET_PERSIST_BY_APP(conn) \ @@ -351,8 +358,8 @@ static void* cliWorkThread(void* arg); static void cliReleaseUnfinishedMsg(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; - for (int i = 0; i < transQueueSize(&conn->reqMsgs); i++) { - SCliReq* msg = transQueueGet(&conn->reqMsgs, i); + for (int i = 0; i < transQueueSize(&conn->reqs); i++) { + SCliReq* msg = transQueueGet(&conn->reqs, i); if (msg != NULL && msg->ctx != NULL && msg->ctx->ahandle != (void*)0x9527) { if (conn->ctx.freeFunc != NULL && msg->ctx->ahandle != NULL) { conn->ctx.freeFunc(msg->ctx->ahandle); @@ -363,11 +370,11 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { } destroyReq(msg); } - transQueueClear(&conn->reqMsgs); + transQueueClear(&conn->reqs); memset(&conn->ctx, 0, sizeof(conn->ctx)); } bool cliMaySendCachedMsg(SCliConn* conn) { - if (!transQueueEmpty(&conn->reqMsgs)) { + if (!transQueueEmpty(&conn->reqs)) { SCliReq* pCliMsg = NULL; CONN_GET_NEXT_SENDMSG(conn); cliSend(conn); @@ -394,7 +401,7 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { taosWUnLockLatch(&exh->latch); SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); transCtxMerge(&conn->ctx, &t->ctx->userCtx); - (void)transQueuePush(&conn->reqMsgs, t); + (void)transQueuePush(&conn->reqs, t); tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); (void)transReleaseExHandle(transGetRefMgt(), refId); cliSend(conn); @@ -422,10 +429,10 @@ void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } SCliReq* cliFindReqBySeq(SCliConn* conn, int32_t seq) { SCliReq* pReq = NULL; - for (int i = 0; i < transQueueSize(&conn->reqMsgs); i++) { - pReq = transQueueGet(&conn->reqMsgs, i); + for (int i = 0; i < transQueueSize(&conn->reqs); i++) { + pReq = transQueueGet(&conn->reqs, i); if (pReq->seq == seq) { - transQueueRm(&conn->reqMsgs, i); + transQueueRm(&conn->reqs, i); break; } } @@ -436,7 +443,7 @@ SCliReq* cliFindReqBySeq(SCliConn* conn, int32_t seq) { } bool cliShouldAddConnToPool(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; - bool empty = transQueueEmpty(&conn->reqMsgs); + bool empty = transQueueEmpty(&conn->reqs); if (empty) { (void)delConnFromHeapCache(pThrd->connHeapCache, conn); } @@ -534,7 +541,7 @@ void cliHandleResp(SCliConn* conn) { SCliReq* pReq = NULL; SReqCtx* pCtx = NULL; if (CONN_NO_PERSIST_BY_APP(conn)) { - pReq = transQueuePop(&conn->reqMsgs); + pReq = transQueuePop(&conn->reqs); pCtx = pReq ? pReq->ctx : NULL; transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; @@ -620,7 +627,7 @@ static void cliDestroyMsgInExhandle(int64_t refId) { } void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { - if (transQueueEmpty(&pConn->reqMsgs)) { + if (transQueueEmpty(&pConn->reqs)) { if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); @@ -632,7 +639,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { STrans* pInst = pThrd->pInst; bool once = false; do { - SCliReq* pReq = transQueuePop(&pConn->reqMsgs); + SCliReq* pReq = transQueuePop(&pConn->reqs); if (pReq == NULL && once) { break; @@ -685,7 +692,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { } destroyReq(pReq); tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); - } while (!transQueueEmpty(&pConn->reqMsgs)); + } while (!transQueueEmpty(&pConn->reqs)); if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); transUnrefCliHandle(pConn); } @@ -794,6 +801,93 @@ static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) { return conn; } +static int32_t getOrCreateMsgList(SCliThrd* pThrd, const char* key, SConnList** ppList) { + int32_t code = 0; + void* pool = pThrd->pool; + size_t klen = strlen(key); + SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); + if (plist == NULL) { + SConnList list = {0}; + code = taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); + if (code != 0) { + return code; + } + + plist = taosHashGet(pool, key, klen); + if (plist == NULL) { + return TSDB_CODE_INVALID_PTR; + } + + SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); + if (nList == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + QUEUE_INIT(&nList->msgQ); + nList->numOfConn++; + + QUEUE_INIT(&plist->conns); + plist->list = nList; + *ppList = plist; + } else { + *ppList = plist; + } + return 0; +} +static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** ppConn) { + int32_t code = 0; + void* pool = pThrd->pool; + STrans* pInst = pThrd->pInst; + // size_t klen = strlen(key); + + SConnList* plist = NULL; + code = getOrCreateMsgList(pThrd, key, &plist); + if (code != 0) { + return code; + } + + if (QUEUE_IS_EMPTY(&plist->conns)) { + if (plist->list->numOfConn >= pInst->connLimitNum) { + return TSDB_CODE_RPC_MAX_SESSIONS; + } + return TSDB_CODE_RPC_NETWORK_BUSY; + } + + queue* h = QUEUE_TAIL(&plist->conns); + plist->size -= 1; + QUEUE_REMOVE(h); + + SCliConn* conn = QUEUE_DATA(h, SCliConn, q); + conn->status = ConnNormal; + QUEUE_INIT(&conn->q); + + if (conn->task != NULL) { + SDelayTask* task = conn->task; + conn->task = NULL; + transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, task); + } + + tDebug("conn %p get from pool, pool size:%d, dst:%s", conn, conn->list->size, conn->dstAddr); + + return 0; +} + +// code +static int32_t cliGetConnOrCreate(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { + // impl later + char* fqdn = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); + uint16_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); + char addr[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(addr, fqdn, port); + + int32_t code = cliGetConnFromPool(pThrd, addr, pConn); + if (code == TSDB_CODE_RPC_MAX_SESSIONS) { + return code; + } else if (code == TSDB_CODE_RPC_NETWORK_BUSY) { + code = cliCreateConn2(pThrd, pReq, pConn); + } else { + } + return code; +} static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliReq** pReq) { void* pool = pThrd->pool; STrans* pInst = pThrd->pInst; @@ -899,7 +993,6 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliReq** pReq) { conn->status = ConnNormal; QUEUE_INIT(&conn->q); tDebug("conn %p get from pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); - if (conn->task != NULL) { transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); conn->task = NULL; @@ -941,7 +1034,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { pReq->ctx->task = NULL; transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); - (void)transQueuePush(&conn->reqMsgs, pReq); + (void)transQueuePush(&conn->reqs, pReq); conn->status = ConnNormal; cliSend(conn); @@ -1069,15 +1162,59 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } } +static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) { + SCliConn* pConn = NULL; + + int32_t code = cliCreateConn(pThrd, &pConn); + if (code != 0) { + return code; + } + + char addr[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + + pConn->dstAddr = taosStrdup(addr); + code = addConnToHeapCache(pThrd->connHeapCache, pConn); + + transQueuePush(&pConn->reqs, pReq); + return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); +} + static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { int32_t code = 0; - int8_t registed = 0; SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); if (conn == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } + transReqQueueInit(&conn->wreqQueue); + QUEUE_INIT(&conn->q); + conn->hostThrd = pThrd; + conn->status = ConnNormal; + conn->broken = false; + + TAOS_CHECK_GOTO(transQueueInit(&conn->reqs, NULL), NULL, _failed); + + TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); + + transRefCliHandle(conn); + + transReqQueueInit(&conn->wreqQueue); + + TAOS_CHECK_GOTO(transQueueInit(&conn->reqs, 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); + conn->seq = 0; + + TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); + // read/write stream handle conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); if (conn->stream == NULL) { @@ -1092,66 +1229,18 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { TAOS_CHECK_GOTO(code, NULL, _failed); } - registed = 1; conn->stream->data = conn; - conn->connReq.data = conn; - transReqQueueInit(&conn->wreqQueue); - QUEUE_INIT(&conn->q); - conn->hostThrd = pThrd; - conn->status = ConnNormal; - conn->broken = false; - - TAOS_CHECK_GOTO(transQueueInit(&conn->reqMsgs, NULL), NULL, _failed); - - TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); - - transRefCliHandle(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); - (void)uv_timer_init(pThrd->loop, timer); - } - timer->data = conn; - - conn->timer = timer; - conn->connReq.data = conn; - transReqQueueInit(&conn->wreqQueue); - - TAOS_CHECK_GOTO(transQueueInit(&conn->reqMsgs, 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); - conn->seq = 0; - // allocConnRef(conn, false); - - TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); - *pCliConn = conn; return code; _failed: - if (registed == 1) { - uv_close((uv_handle_t*)conn->stream, cliDestroy); - } else { - if (conn) { - taosMemoryFree(conn->stream); - (void)transDestroyBuffer(&conn->readBuf); - transQueueDestroy(&conn->reqMsgs); - } - taosMemoryFree(conn); + if (conn) { + taosMemoryFree(conn->stream); + (void)transDestroyBuffer(&conn->readBuf); + transQueueDestroy(&conn->reqs); } + taosMemoryFree(conn); return code; } static void cliDestroyConn(SCliConn* conn, bool clear) { @@ -1217,10 +1306,10 @@ static void cliDestroy(uv_handle_t* handle) { } static bool cliHandleNoResp(SCliConn* conn) { bool res = false; - if (!transQueueEmpty(&conn->reqMsgs)) { - SCliReq* pReq = transQueueGet(&conn->reqMsgs, 0); + if (!transQueueEmpty(&conn->reqs)) { + SCliReq* pReq = transQueueGet(&conn->reqs, 0); if (REQUEST_NO_RESP(&pReq->msg)) { - (void)transQueuePop(&conn->reqMsgs); + (void)transQueuePop(&conn->reqs); destroyReq(pReq); res = true; } @@ -1242,7 +1331,7 @@ static void cliSendCb(uv_write_t* req, int status) { SCliConn* pConn = transReqQueueRemove(req); if (pConn == NULL) return; - SCliReq* pReq = transQueueGet(&pConn->reqMsgs, 0); + SCliReq* pReq = transQueueGet(&pConn->reqs, 0); if (pReq != NULL) { int64_t cost = taosGetTimestampUs() - pReq->st; if (cost > 1000 * 50) { @@ -1274,8 +1363,8 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { int32_t code = -1; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - while (!transQueueEmpty(&conn->reqMsgs)) { - SCliReq* pReq = transQueuePop(&conn->reqMsgs); + while (!transQueueEmpty(&conn->reqs)) { + SCliReq* pReq = transQueuePop(&conn->reqs); ASSERT(pReq->type != Release); ASSERT(REQUEST_NO_RESP(&pReq->msg) == 0); @@ -1317,7 +1406,7 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { void cliSendBatch_shareConn(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - int32_t size = transQueueSize(&pConn->reqMsgs); + int32_t size = transQueueSize(&pConn->reqs); int32_t totalLen = 0; if (size == 0) { @@ -1330,7 +1419,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int j = 0; for (int i = 0; i < size; i++) { - SCliReq* pCliMsg = transQueueGet(&pConn->reqMsgs, i); + SCliReq* pCliMsg = transQueueGet(&pConn->reqs, i); if (pCliMsg->sent == 1) { continue; } @@ -1478,7 +1567,7 @@ void cliSend(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - if (transQueueEmpty(&pConn->reqMsgs)) { + if (transQueueEmpty(&pConn->reqs)) { tError("%s conn %p not msg to send", pInst->label, pConn); cliHandleExcept(pConn, -1); return; @@ -1567,19 +1656,13 @@ static void cliDestroyBatch(SCliBatch* pBatch) { taosMemoryFree(pBatch); } -static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { +static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { + int32_t lino = 0; STrans* pInst = pThrd->pInst; uint32_t ipaddr; int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, ip, &ipaddr); if (code != 0) { - cliResetConnTimer(conn); - if (conn->pBatch != NULL) { - cliHandleFastFail(conn, -1); - } else { - cliHandleBatch_shareConnExcept(conn); - } - - return; + TAOS_CHECK_GOTO(code, &lino, _exception); } struct sockaddr_in addr; @@ -1590,32 +1673,40 @@ static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { tTrace("%s conn %p try to connect to %s", pInst->label, conn, conn->dstAddr); int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); - if (fd == -1) { - tError("%s conn %p failed to create socket, reason:%s", transLabel(pInst), conn, - tstrerror(TAOS_SYSTEM_ERROR(errno))); - cliHandleFastFail(conn, -1); - return; + if (fd < 0) { + TAOS_CHECK_GOTO(terrno, &lino, _exception); } int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); if (ret != 0) { tError("%s conn %p failed to set stream, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); - cliHandleFastFail(conn, -1); - return; + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception); } ret = transSetConnOption((uv_tcp_t*)conn->stream, 20); if (ret != 0) { tError("%s conn %p failed to set socket opt, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); - cliHandleFastFail(conn, -1); - return; + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception); + return code; } + 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, _exception); + } + + tDebug("no available timer, create a timer %p", timer); + (void)uv_timer_init(pThrd->loop, timer); + } + timer->data = conn; + conn->timer = timer; ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { - cliResetConnTimer(conn); + // cliResetConnTimer(conn); cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); cliHandleFastFail(conn, -1); - return; + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } ret = uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); @@ -1624,9 +1715,13 @@ static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { cliResetConnTimer(conn); cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); cliHandleFastFail(conn, -1); - return; + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } - return; + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; +_exception: + tError("%s conn %p failed to start timer, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); + taosMemoryFree(conn); // free conn later + return code; } static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { if (pBatch == NULL || pBatch->wLen == 0 || QUEUE_IS_EMPTY(&pBatch->wq)) { @@ -1662,7 +1757,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { conn->pBatch = pBatch; conn->dstAddr = taosStrdup(pList->dst); - return cliDoConn(pThrd, conn, pList->ip, pList->port); + (void)cliDoConn(pThrd, conn, pList->ip, pList->port); } conn->pBatch = pBatch; @@ -1707,7 +1802,7 @@ static void cliSendBatchCb(uv_write_t* req, int status) { static void cliHandleFastFail_resp(SCliConn* pConn, int status) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - SCliReq* pReq = transQueueGet(&pConn->reqMsgs, 0); + SCliReq* pReq = transQueueGet(&pConn->reqs, 0); STraceId* trace = &pReq->msg.info.traceId; tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), @@ -1784,27 +1879,27 @@ static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code) { SReqCtx* pCtx = pReq->ctx; STrans* pInst = pThrd->pInst; - STransMsg transMsg = {0}; - transMsg.contLen = 0; - transMsg.pCont = NULL; - transMsg.code = code; - transMsg.msgType = pReq->msg.msgType + 1; - transMsg.info.ahandle = pReq->ctx->ahandle; - transMsg.info.traceId = pReq->msg.info.traceId; - transMsg.info.hasEpSet = false; - transMsg.info.cliVer = pInst->compatibilityVer; + STransMsg resp = {0}; + resp.contLen = 0; + resp.pCont = NULL; + resp.code = code; + resp.msgType = pReq->msg.msgType + 1; + resp.info.ahandle = pReq->ctx->ahandle; + resp.info.traceId = pReq->msg.info.traceId; + resp.info.hasEpSet = false; + resp.info.cliVer = pInst->compatibilityVer; if (pCtx->pSem != NULL) { if (pCtx->pRsp == NULL) { } else { - memcpy((char*)pCtx->pRsp, (char*)&transMsg, sizeof(transMsg)); + memcpy((char*)pCtx->pRsp, (char*)&resp, sizeof(resp)); } } else { - pInst->cfp(pInst->parent, &transMsg, NULL); + pInst->cfp(pInst->parent, &resp, NULL); } destroyReq(pReq); } -static void cliHandleQuit(SCliReq* pReq, SCliThrd* pThrd) { +static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq) { if (!transAsyncPoolIsEmpty(pThrd->asyncPool)) { pThrd->stopMsg = pReq; return; @@ -1817,7 +1912,7 @@ static void cliHandleQuit(SCliReq* pReq, SCliThrd* pThrd) { (void)destroyConnPool(pThrd); (void)uv_walk(pThrd->loop, cliWalkCb, NULL); } -static void cliHandleRelease(SCliReq* pReq, SCliThrd* pThrd) { +static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { int64_t refId = (int64_t)(pReq->msg.info.handle); SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); if (exh == NULL) { @@ -1835,7 +1930,7 @@ static void cliHandleRelease(SCliReq* pReq, SCliThrd* pThrd) { if (T_REF_VAL_GET(conn) == 2) { transUnrefCliHandle(conn); - if (!transQueuePush(&conn->reqMsgs, pReq)) { + if (!transQueuePush(&conn->reqs, pReq)) { return; } cliSend(conn); @@ -1844,12 +1939,12 @@ static void cliHandleRelease(SCliReq* pReq, SCliThrd* pThrd) { destroyReq(pReq); } } -static void cliHandleUpdate(SCliReq* pReq, SCliThrd* pThrd) { +static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { SReqCtx* pCtx = pReq->ctx; pThrd->cvtAddr = pCtx->cvtAddr; destroyReq(pReq); } -static void cliHandleFreeById(SCliReq* pReq, SCliThrd* pThrd) { +static void cliHandleFreeById(SCliThrd* pThrd, SCliReq* pReq) { int32_t code = 0; int64_t refId = (int64_t)(pReq->msg.info.handle); SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); @@ -1868,7 +1963,7 @@ static void cliHandleFreeById(SCliReq* pReq, SCliThrd* pThrd) { } tDebug("do free conn %p by id %" PRId64 "", conn, refId); - int32_t size = transQueueSize(&conn->reqMsgs); + int32_t size = transQueueSize(&conn->reqs); if (size == 0) { // already recv, and notify upper layer TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); @@ -2041,225 +2136,84 @@ static void doFreeTimeoutMsg(void* param) { taosMemoryFree(arg); } -static int32_t getOrCreateHeapIfNotExist(SHashObj* pConnHeapCache, char* key, SHeap** pHeap) { - int32_t code = 0; - size_t klen = strlen(key); +void cliHandleReq__shareConn(SCliThrd* pThrd, SCliReq* pReq) { + int32_t code = 0; + int32_t lino = 0; + STransMsg resp = {0}; - SHeap* p = taosHashGet(pConnHeapCache, key, klen); - if (p == NULL) { - SHeap heap = {0}; - code = transHeapInit(&heap, compareHeapNode); - if (code != 0) { - tError("failed to init heap cache for key:%s, reason: %s", key, tstrerror(code)); - return code; - } + code = (pThrd->initCb)(pThrd, pReq, NULL); + TAOS_CHECK_GOTO(code, &lino, _exception); - code = taosHashPut(pConnHeapCache, key, klen, &heap, sizeof(heap)); - if (code != 0) { - transHeapDestroy(&heap); - tError("failed to put heap to cache for key:%s, reason: %s", key, tstrerror(code)); - } - p = taosHashGet(pConnHeapCache, key, klen); - if (p == NULL) { - code = TSDB_CODE_INVALID_PARA; + STraceId* trace = &pReq->msg.info.traceId; + STrans* pInst = pThrd->pInst; + + char addr[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + + SCliConn* pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); + if (pConn == NULL) { + tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); + bool ignore = false; + pConn = getConnFromPool(pThrd, addr, &ignore); + if (pConn != NULL) { + addConnToHeapCache(pThrd->connHeapCache, pConn); + transQueuePush(&pConn->reqs, pReq); + return cliSendBatch_shareConn(pConn); } + } else { + tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); + transQueuePush(&pConn->reqs, pReq); + cliSendBatch_shareConn(pConn); + return; } - *pHeap = p; - return code; + + code = cliCreateConn(pThrd, &pConn); + pConn->dstAddr = taosStrdup(addr); + code = addConnToHeapCache(pThrd->connHeapCache, pConn); + + transQueuePush(&pConn->reqs, pReq); + cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + +_exception: + + resp.code = code; + (void)(pThrd->notifyExceptCb)(pThrd, pReq, &resp); + return; } -static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { - int code = 0; - SHeap* pHeap = NULL; +void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { + int32_t lino = 0; + STransMsg resp = {0}; + int32_t code = (pThrd->initCb)(pThrd, pReq, NULL); + TAOS_CHECK_GOTO(code, &lino, _exception); + + STrans* pInst = pThrd->pInst; SCliConn* pConn = NULL; - code = getOrCreateHeapIfNotExist(pConnHeapCache, key, &pHeap); - if (code != 0) { - tDebug("failed to get conn heap from cache for key:%s", key); - return NULL; - } - code = transHeapGet(pHeap, &pConn); - if (code != 0) { - tDebug("failed to get conn from heap cache for key:%s", key); - return NULL; - } - return pConn; -} -static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { - SHeap* p = NULL; - int32_t code = getOrCreateHeapIfNotExist(pConnHeapCacahe, pConn->dstAddr, &p); - if (code != 0) { - return code; + code = cliGetConnOrCreate(pThrd, pReq, &pConn); + if (code == TSDB_CODE_RPC_MAX_SESSIONS) { + TAOS_CHECK_GOTO(code, &lino, _exception); + } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + // do nothing, notifyCb + return; + } else { } - return transHeapInsert(p, pConn); + + tTrace("%s conn %p ready", pInst->label, pConn); +_exception: + + resp.code = code; + (void)(pThrd->notifyExceptCb)(pThrd, pReq, &resp); + return; } -static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { - SHeap* p = taosHashGet(pConnHeapCache, pConn->dstAddr, strlen(pConn->dstAddr)); - if (p == NULL) { - tDebug("failed to get heap cache for key:%s, no need to del", pConn->dstAddr); - return 0; +void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq) { + STrans* pInst = pThrd->pInst; + if (pInst->shareConn == 1) { + return cliHandleReq__shareConn(pThrd, pReq); + } else { + return cliHandleReq__noShareConn(pThrd, pReq); } - int32_t code = transHeapDelete(p, pConn); - if (code != 0) { - tDebug("failed to delete conn %p from heap cache since %s", pConn, tstrerror(code)); - } - return code; -} - -void cliHandleReq__shareConn(SCliReq* pReq, SCliThrd* pThrd) { - // int32_t code = 0; - - // STraceId* trace = &pReq->msg.info.traceId; - // STrans* pInst = pThrd->pInst; - - // code = cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); - // if (code != 0) { - // // TODO: notifyCb - // destroyReq(pReq); - // return; - // } - - // char addr[TSDB_FQDN_LEN + 64] = {0}; - // CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); - - // SCliConn* pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); - // if (pConn == NULL) { - // tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); - // bool ignore = false; - // pConn = getConnFromPool(pThrd, addr, &ignore); - // if (pConn != NULL) { - // addConnToHeapCache(pThrd->connHeapCache, pConn); - // transQueuePush(&pConn->reqMsgs, pReq); - // return cliSendBatch_shareConn(pConn); - // } - // } else { - // tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); - // transQueuePush(&pConn->reqMsgs, pReq); - // cliSendBatch_shareConn(pConn); - // return; - // } - - // code = cliCreateConn(pThrd, &pConn); - // pConn->dstAddr = taosStrdup(addr); - // code = addConnToHeapCache(pThrd->connHeapCache, pConn); - - // transQueuePush(&pConn->reqMsgs, pReq); - // return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); -} - -void cliHandleReq__noShareConn(SCliReq* pReq, SCliThrd* pThrd) { - // int32_t code; - // STrans* pInst = pThrd->pInst; - // code = cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); - // if (code != 0) { - // // notifyCb - // destroyReq(pReq); - // } - - // char* fqdn = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); - // uint16_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); - // char addr[TSDB_FQDN_LEN + 64] = {0}; - // CONN_CONSTRUCT_HASH_KEY(addr, fqdn, port); - - // bool ignore = false; - // SCliConn* conn = cliGetConn(&pReq, pThrd, &ignore, addr); - // if (ignore == true) { - // // persist conn already release by server - // STransMsg resp = {0}; - // if (pReq->type != Release) { - // (void)cliBuildExceptRespAndNotifyCb(pThrd, pReq, 0); - // } - // destroyReq(pReq); - // return; - // } - // if (conn == NULL && pReq == NULL) { - // return; - // } - // STraceId* trace = &pReq->msg.info.traceId; - - // if (conn != NULL) { - // transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); - // (void)transQueuePush(&conn->reqMsgs, pReq); - // cliSend(conn); - // } else { - // code = cliCreateConn(pThrd, &conn); - // if (code != 0) { - // tError("%s failed to create conn, reason:%s", pInst->label, tstrerror(code)); - // (void)cliBuildExceptRespAndNotifyCb(pThrd, pReq, code); - // destroyReq(pReq); - // return; - // } - - // specifyConnRef(conn, true, (int64_t)pReq->msg.info.handle); - - // transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); - // (void)transQueuePush(&conn->reqMsgs, pReq); - - // conn->dstAddr = taosStrdup(addr); - // if (conn->dstAddr == NULL) { - // tError("%s conn %p failed to send batch msg, reason:%s", transLabel(pInst), conn, - // tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - // cliHandleFastFail(conn, -1); - // return; - // } - - // uint32_t ipaddr; - // int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, fqdn, &ipaddr); - // if (code != 0) { - // cliResetConnTimer(conn); - // cliHandleExcept(conn, code); - // return; - // } - - // struct sockaddr_in addr; - // addr.sin_family = AF_INET; - // addr.sin_addr.s_addr = ipaddr; - // addr.sin_port = (uint16_t)htons(port); - - // tGTrace("%s conn %p try to connect to %s", pInst->label, conn, conn->dstAddr); - // int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); - // if (fd == -1) { - // tGError("%s conn %p failed to create socket, reason:%s", transLabel(pInst), conn, - // tstrerror(TAOS_SYSTEM_ERROR(errno))); - // cliHandleExcept(conn, -1); - // 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(pInst), 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(pInst), conn, uv_err_name(ret)); - // cliHandleExcept(conn, -1); - // return; - // } - - // ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); - // if (ret != 0) { - // cliResetConnTimer(conn); - // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - // cliHandleFastFail(conn, ret); - // return; - // } - // (void)uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); - // } - // tGTrace("%s conn %p ready", pInst->label, conn); -} - -void cliHandleReq(SCliReq* pReq, SCliThrd* pThrd) { - // STrans* pInst = pThrd->pInst; - // if (pInst->shareConn == 1) { - // return cliHandleReq__shareConn(pReq, pThrd); - // } else { - // return cliHandleReq__noShareConn(pReq, pThrd); - // } } static void cliDealReq(queue* wq, SCliThrd* pThrd) { @@ -2275,7 +2229,7 @@ static void cliDealReq(queue* wq, SCliThrd* pThrd) { pThrd->stopMsg = pReq; continue; } - (*cliAsyncHandle[pReq->type])(pReq, pThrd); + (*cliAsyncHandle[pReq->type])(pThrd, pReq); count++; } if (count >= 2) { @@ -2434,7 +2388,7 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { } continue; } - (*cliAsyncHandle[pReq->type])(pReq, pThrd); + (*cliAsyncHandle[pReq->type])(pThrd, pReq); count++; } @@ -2466,16 +2420,16 @@ static void cliAsyncCb(uv_async_t* handle) { cliDealFunc[pInst->supportBatch](&wq, pThrd); - if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd); + if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd, pThrd->stopMsg); } void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { transCtxCleanup(&conn->ctx); cliReleaseUnfinishedMsg(conn); if (destroy == 1) { - transQueueDestroy(&conn->reqMsgs); + transQueueDestroy(&conn->reqs); } else { - transQueueClear(&conn->reqMsgs); + transQueueClear(&conn->reqs); } } @@ -2483,8 +2437,8 @@ void cliConnFreeMsgs(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - for (int i = 0; i < transQueueSize(&conn->reqMsgs); i++) { - SCliReq* cmsg = transQueueGet(&conn->reqMsgs, i); + for (int i = 0; i < transQueueSize(&conn->reqs); i++) { + SCliReq* cmsg = transQueueGet(&conn->reqs, i); if (cmsg->type == Release || REQUEST_NO_RESP(&cmsg->msg) || cmsg->msg.msgType == TDMT_SCH_DROP_TASK) { continue; } @@ -2507,8 +2461,8 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { (void)transClearBuffer(&conn->readBuf); transFreeMsg(transContFromHead((char*)pHead)); - for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->reqMsgs); i++) { - SCliReq* pReq = transQueueGet(&conn->reqMsgs, i); + for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->reqs); i++) { + SCliReq* pReq = transQueueGet(&conn->reqs, i); if (pReq->type == Release) { ASSERTS(pReq == NULL, "trans-cli recv invaid release-req"); tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, @@ -2629,6 +2583,27 @@ _err: return NULL; } +int32_t initCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { + SCliThrd* pThrd = pThrd; + return cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); +} +int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { + STrans* pInst = ((SCliThrd*)thrd)->pInst; + int32_t code = cliBuildExceptResp(pReq, pResp); + + if (code != 0) { + return code; + } + pResp->info.cliVer = pInst->compatibilityVer; + pInst->cfp(pInst->parent, pResp, NULL); + return code; +} + +int32_t notfiyCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { + // impl later + return 0; +} + static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { int32_t code = 0; STrans* pInst = trans; @@ -2714,6 +2689,10 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } + pThrd->initCb = initCb; + pThrd->notifyCb = notfiyCb; + pThrd->notifyExceptCb = notifyExceptCb; + pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pInst->idleTime); pThrd->pInst = trans; pThrd->quit = false; @@ -2841,7 +2820,7 @@ FORCE_INLINE int cliRBChoseIdx(STrans* pInst) { } static FORCE_INLINE void doDelayTask(void* param) { STaskArg* arg = param; - cliHandleReq((SCliReq*)arg->param1, (SCliThrd*)arg->param2); + cliHandleReq((SCliThrd*)arg->param2, (SCliReq*)arg->param1); taosMemoryFree(arg); } @@ -3771,11 +3750,76 @@ _exception: return code; } +static int32_t getOrCreateHeapIfNotExist(SHashObj* pConnHeapCache, char* key, SHeap** pHeap) { + int32_t code = 0; + size_t klen = strlen(key); + + SHeap* p = taosHashGet(pConnHeapCache, key, klen); + if (p == NULL) { + SHeap heap = {0}; + code = transHeapInit(&heap, compareHeapNode); + if (code != 0) { + tError("failed to init heap cache for key:%s, reason: %s", key, tstrerror(code)); + return code; + } + + code = taosHashPut(pConnHeapCache, key, klen, &heap, sizeof(heap)); + if (code != 0) { + transHeapDestroy(&heap); + tError("failed to put heap to cache for key:%s, reason: %s", key, tstrerror(code)); + } + p = taosHashGet(pConnHeapCache, key, klen); + if (p == NULL) { + code = TSDB_CODE_INVALID_PARA; + } + } + *pHeap = p; + return code; +} + +static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { + int code = 0; + SHeap* pHeap = NULL; + SCliConn* pConn = NULL; + code = getOrCreateHeapIfNotExist(pConnHeapCache, key, &pHeap); + if (code != 0) { + tDebug("failed to get conn heap from cache for key:%s", key); + return NULL; + } + code = transHeapGet(pHeap, &pConn); + if (code != 0) { + tDebug("failed to get conn from heap cache for key:%s", key); + return NULL; + } + return pConn; +} +static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { + SHeap* p = NULL; + + int32_t code = getOrCreateHeapIfNotExist(pConnHeapCacahe, pConn->dstAddr, &p); + if (code != 0) { + return code; + } + return transHeapInsert(p, pConn); +} + +static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { + SHeap* p = taosHashGet(pConnHeapCache, pConn->dstAddr, strlen(pConn->dstAddr)); + if (p == NULL) { + tDebug("failed to get heap cache for key:%s, no need to del", pConn->dstAddr); + return 0; + } + int32_t code = transHeapDelete(p, pConn); + if (code != 0) { + tDebug("failed to delete conn %p from heap cache since %s", pConn, tstrerror(code)); + } + return code; +} // conn heap int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { SCliConn* args1 = container_of(a, SCliConn, node); SCliConn* args2 = container_of(b, SCliConn, node); - if (transQueueSize(&args1->reqMsgs) > transQueueSize(&args2->reqMsgs)) { + if (transQueueSize(&args1->reqs) > transQueueSize(&args2->reqs)) { return 0; } return 1; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 5dc375da24..60058bbbd2 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -376,10 +376,6 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) { STransCtxVal* sVal = (STransCtxVal*)iter; key = taosHashGetKey(sVal, &klen); - // STransCtxVal* dVal = taosHashGet(dst->args, key, klen); - // if (dVal) { - // dst->freeFunc(dVal->val); - // } (void)taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal)); iter = taosHashIterate(src->args, iter); } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index b307c4ac4b..e03913d0e7 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -59,6 +59,7 @@ 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") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_IN_PROCESS, "rpc async in process") //common & util TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized") From a367e6a0d3b4e8b09a5c655e7050c7e2f9c56177 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 24 Aug 2024 18:04:15 +0800 Subject: [PATCH 036/240] refactor transport --- source/libs/transport/src/transCli.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 12022f495f..9a0f5fa450 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -872,7 +872,7 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p } // code -static int32_t cliGetConnOrCreate(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { +static int32_t cliGetOrCreateConn(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { // impl later char* fqdn = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); uint16_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); @@ -2190,7 +2190,7 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { STrans* pInst = pThrd->pInst; SCliConn* pConn = NULL; - code = cliGetConnOrCreate(pThrd, pReq, &pConn); + code = cliGetOrCreateConn(pThrd, pReq, &pConn); if (code == TSDB_CODE_RPC_MAX_SESSIONS) { TAOS_CHECK_GOTO(code, &lino, _exception); } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { @@ -2201,7 +2201,6 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { tTrace("%s conn %p ready", pInst->label, pConn); _exception: - resp.code = code; (void)(pThrd->notifyExceptCb)(pThrd, pReq, &resp); return; From bdc446314d09f8ad4b8e5c4acc55ef1b81d31880 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 24 Aug 2024 20:44:40 +0800 Subject: [PATCH 037/240] refactor transport --- source/libs/transport/inc/transComm.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index b811d192bd..9ab2d918b8 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -476,6 +476,8 @@ int32_t subnetDebugInfoToBuf(SubnetUtils* pUtils, char* buf); int32_t transUtilSIpRangeToStr(SIpV4Range* pRange, char* buf); int32_t transUtilSWhiteListToStr(SIpWhiteList* pWhiteList, char** ppBuf); +enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; + #ifdef __cplusplus } #endif From 46447c2bb2a47482cec00885d5688490ec822bfc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 24 Aug 2024 20:44:51 +0800 Subject: [PATCH 038/240] refactor transport --- source/libs/transport/src/transCli.c | 164 +++++++++++++++------------ 1 file changed, 92 insertions(+), 72 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 9a0f5fa450..9f35965431 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -162,7 +162,8 @@ static SCliConn* getConnFromPool(SCliThrd* thread, char* key, bool* exceed); static void addConnToPool(void* pool, SCliConn* conn); static void doCloseIdleConn(void* param); static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); -static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn); +static int32_t cliCreateConn(SCliThrd* pThrd, const SCliReq* pReq, SCliConn** pCliConn); +static int32_t cliDestroyConn2(SCliConn* pConn); static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port); // register conn timer @@ -195,12 +196,11 @@ static int32_t allocConnRef(SCliConn* conn, bool update); static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); void cliResetConnTimer(SCliConn* conn); -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 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, SCliReq** pReq); @@ -1162,31 +1162,62 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } } +static int32_t cliAddReqToConn(SCliConn* conn, SCliReq* pReq) { + if (transQueuePush(&conn->reqs, pReq) != 0) { + return TSDB_CODE_OUT_OF_MEMORY; + } + return 0; +} + +static int32_t cliRmReqFromConn(SCliConn* conn, SCliReq** pReq) { + // do nothing + SCliReq* pTail = transQueuePop(&conn->reqs); + if (pTail == NULL) { + return TSDB_CODE_INVALID_PARA; + } + if (pReq != NULL) { + *pReq = pTail; + } + return 0; +} static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) { SCliConn* pConn = NULL; - int32_t code = cliCreateConn(pThrd, &pConn); + int32_t code = cliCreateConn(pThrd, pReq, &pConn); if (code != 0) { return code; } + code = cliAddReqToConn(pConn, pReq); + code = addConnToHeapCache(pThrd->connHeapCache, pConn); + + code = cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + if (code != TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + cliRmReqFromConn(pConn, NULL); + cliDestroyConn2(pConn); + return code; + } else { + } + return code; +} + +// not any ref, +static int32_t cliDestroyConn2(SCliConn* conn) { return 0; } +static int32_t cliCreateConn(SCliThrd* pThrd, const SCliReq* pReq, SCliConn** pCliConn) { char addr[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); - pConn->dstAddr = taosStrdup(addr); - code = addConnToHeapCache(pThrd->connHeapCache, pConn); - - transQueuePush(&pConn->reqs, pReq); - return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); -} - -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; } + conn->dstAddr = taosStrdup(addr); + if (conn->dstAddr == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_GOTO(code, NULL, _failed); + } transReqQueueInit(&conn->wreqQueue); QUEUE_INIT(&conn->q); @@ -1239,48 +1270,12 @@ _failed: taosMemoryFree(conn->stream); (void)transDestroyBuffer(&conn->readBuf); transQueueDestroy(&conn->reqs); + taosMemoryFree(conn->dstAddr); } taosMemoryFree(conn); return code; } -static void cliDestroyConn(SCliConn* conn, bool clear) { - SCliThrd* pThrd = conn->hostThrd; - tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn); - conn->broken = true; - QUEUE_REMOVE(&conn->q); - QUEUE_INIT(&conn->q); - - conn->broken = true; - if (conn->list == NULL && conn->dstAddr) { - conn->list = taosHashGet((SHashObj*)pThrd->pool, conn->dstAddr, strlen(conn->dstAddr)); - } - - if (conn->list) { - SConnList* list = conn->list; - list->list->numOfConn--; - if (conn->status == ConnInPool) { - list->size--; - } - } - conn->list = NULL; - - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); - conn->refId = -1; - - if (conn->task != NULL) { - transDQCancel(pThrd->timeoutQueue, conn->task); - conn->task = NULL; - } - cliResetConnTimer(conn); - - if (clear) { - if (!uv_is_closing((uv_handle_t*)conn->stream)) { - (void)uv_read_stop(conn->stream); - uv_close((uv_handle_t*)conn->stream, cliDestroy); - } - } -} +static void cliDestroyConn(SCliConn* conn, bool clear) {} static void cliDestroy(uv_handle_t* handle) { if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) { return; @@ -1563,6 +1558,19 @@ _exception: pConn->pBatch = NULL; return; } + + +int32_t cliSend2(SCliConn* pConn) { + +} +int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { + int32_t code = 0; + transQueuePush(&pConn->reqs, pCliMsg); + cliSend(pConn); + + return 0; +} + void cliSend(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; @@ -1662,7 +1670,7 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { uint32_t ipaddr; int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, ip, &ipaddr); if (code != 0) { - TAOS_CHECK_GOTO(code, &lino, _exception); + TAOS_CHECK_GOTO(code, &lino, _exception1); } struct sockaddr_in addr; @@ -1674,25 +1682,25 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); if (fd < 0) { - TAOS_CHECK_GOTO(terrno, &lino, _exception); + TAOS_CHECK_GOTO(terrno, &lino, _exception1); } int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); if (ret != 0) { tError("%s conn %p failed to set stream, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); - TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); } ret = transSetConnOption((uv_tcp_t*)conn->stream, 20); if (ret != 0) { tError("%s conn %p failed to set socket opt, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); - TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); return code; } 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, _exception); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception1); } tDebug("no available timer, create a timer %p", timer); @@ -1703,24 +1711,33 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { - // cliResetConnTimer(conn); - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, -1); - return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + tError("%s conn %p failed to connect, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception2); } ret = uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); if (ret != 0) { tError("%s conn %p failed to start timer, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); - cliResetConnTimer(conn); - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, -1); - return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception2); } + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; -_exception: - tError("%s conn %p failed to start timer, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); - taosMemoryFree(conn); // free conn later + +_exception1: + tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, uv_err_name(code)); + // taosMemoryFree(conn); // free conn later + return code; + +_exception2: + // already registered to uv, callback handle error + tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, uv_err_name(code)); + // cliRmReqFromConn(conn, NULL); + + // cliResetConnTimer(conn); + // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); + // cliHandleFastFail(conn, code); + + // // taosMemoryFree(conn); return code; } static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { @@ -1747,7 +1764,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { return; } if (conn == NULL) { - code = cliCreateConn(pThrd, &conn); + code = cliCreateConn(pThrd, NULL, &conn); if (code != 0) { tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d, reason:%s", pInst->label, pBatch->wLen, pBatch->batchSize, pInst->connLimitNum, tstrerror(code)); @@ -2167,7 +2184,7 @@ void cliHandleReq__shareConn(SCliThrd* pThrd, SCliReq* pReq) { return; } - code = cliCreateConn(pThrd, &pConn); + code = cliCreateConn(pThrd, NULL, &pConn); pConn->dstAddr = taosStrdup(addr); code = addConnToHeapCache(pThrd->connHeapCache, pConn); @@ -2197,9 +2214,12 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { // do nothing, notifyCb return; } else { + code = cliSendReq(pConn, pReq); } tTrace("%s conn %p ready", pInst->label, pConn); + return; + _exception: resp.code = code; (void)(pThrd->notifyExceptCb)(pThrd, pReq, &resp); From 4f5b6eb2c783a8ee89c1c52e8ceb5fe4a00227c5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 26 Aug 2024 10:13:06 +0800 Subject: [PATCH 039/240] refactor transport --- source/libs/transport/src/transCli.c | 93 +++++++++++++++++----------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 9f35965431..2bf5fa11ac 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -90,6 +90,8 @@ typedef struct SCliConn { int64_t refId; int32_t seq; int32_t shareCnt; + + int8_t registered; } SCliConn; typedef struct SCliReq { @@ -196,11 +198,11 @@ static int32_t allocConnRef(SCliConn* conn, bool update); static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); void cliResetConnTimer(SCliConn* conn); -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 cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); +static void cliDestroy(uv_handle_t* handle); +static int32_t 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, SCliReq** pReq); @@ -324,6 +326,17 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); } \ } while (0) +static int32_t cliConnFindToSendMsg(SCliConn* pConn, SCliReq** pReq) { + int32_t code = 0; + for (int32_t i = 0; i < transQueueSize(&pConn->reqs); i++) { + SCliReq* p = transQueueGet(&pConn->reqs, i); + if (p->sent == 0) { + *pReq = p; + return 0; + } + } + return TSDB_CODE_OUT_OF_RANGE; +} #define CONN_SET_PERSIST_BY_APP(conn) \ do { \ if (conn->status == ConnNormal) { \ @@ -377,7 +390,7 @@ bool cliMaySendCachedMsg(SCliConn* conn) { if (!transQueueEmpty(&conn->reqs)) { SCliReq* pCliMsg = NULL; CONN_GET_NEXT_SENDMSG(conn); - cliSend(conn); + (void)cliSend(conn); return true; } return false; @@ -404,7 +417,7 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { (void)transQueuePush(&conn->reqs, t); tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); (void)transReleaseExHandle(transGetRefMgt(), refId); - cliSend(conn); + (void)cliSend(conn); return true; } taosWUnLockLatch(&exh->latch); @@ -1037,7 +1050,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { (void)transQueuePush(&conn->reqs, pReq); conn->status = ConnNormal; - cliSend(conn); + (void)cliSend(conn); return; } @@ -1195,6 +1208,7 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) if (code != TSDB_CODE_RPC_ASYNC_IN_PROCESS) { cliRmReqFromConn(pConn, NULL); cliDestroyConn2(pConn); + delConnFromHeapCache(pThrd->connHeapCache, pConn); return code; } else { } @@ -1202,7 +1216,15 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) } // not any ref, -static int32_t cliDestroyConn2(SCliConn* conn) { return 0; } +static int32_t cliDestroyConn2(SCliConn* conn) { + if (conn->registered == 0) { + taosMemoryFree(conn->dstAddr); + taosMemoryFree(conn); + } else { + cliDestroyConn(conn, true); + } + return 0; +} static int32_t cliCreateConn(SCliThrd* pThrd, const SCliReq* pReq, SCliConn** pCliConn) { char addr[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); @@ -1559,37 +1581,33 @@ _exception: return; } - -int32_t cliSend2(SCliConn* pConn) { - -} +// int32_t cliSend2(SCliConn* pConn) {} int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; transQueuePush(&pConn->reqs, pCliMsg); - cliSend(pConn); - - return 0; + code = cliSend(pConn); + return code; } -void cliSend(SCliConn* pConn) { +int32_t cliSend(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; + SCliReq* pCliReq = NULL; + int32_t code = cliConnFindToSendMsg(pConn, &pCliReq); - if (transQueueEmpty(&pConn->reqs)) { - tError("%s conn %p not msg to send", pInst->label, pConn); - cliHandleExcept(pConn, -1); - return; + if (code != 0) { + return code; } - SCliReq* pCliMsg = NULL; - CONN_GET_NEXT_SENDMSG(pConn); - pCliMsg->sent = 1; + SReqCtx* pCtx = pCliReq->ctx; - SReqCtx* pCtx = pCliMsg->ctx; - - STransMsg* pReq = (STransMsg*)(&pCliMsg->msg); + STransMsg* pReq = (STransMsg*)(&pCliReq->msg); if (pReq->pCont == 0) { pReq->pCont = (void*)rpcMallocCont(0); + if (pReq->pCont == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tDebug("malloc memory: %p", pReq->pCont); pReq->contLen = 0; } @@ -1603,7 +1621,7 @@ void cliSend(SCliConn* pConn) { pHead->persist = REQUEST_PERSIS_HANDLE(pReq) ? 1 : 0; pHead->msgType = pReq->msgType; pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; + pHead->release = REQUEST_RELEASE_HANDLE(pCliReq) ? 1 : 0; memcpy(pHead->user, pInst->user, strlen(pInst->user)); pHead->traceId = pReq->info.traceId; pHead->magicNum = htonl(TRANS_MAGIC_NUM); @@ -1636,18 +1654,19 @@ void cliSend(SCliConn* pConn) { tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), tstrerror(TSDB_CODE_OUT_OF_MEMORY)); cliHandleExcept(pConn, -1); - return; + return TSDB_CODE_OUT_OF_MEMORY; } + pCliReq->sent = 1; int status = uv_write(req, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); if (status != 0) { tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), uv_err_name(status)); cliHandleExcept(pConn, -1); + return TSDB_CODE_THIRDPARTY_ERROR; } - return; -_RETURN: - return; + + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } static void cliDestroyBatch(SCliBatch* pBatch) { @@ -1720,7 +1739,7 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { tError("%s conn %p failed to start timer, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception2); } - + conn->registered = 1; return TSDB_CODE_RPC_ASYNC_IN_PROCESS; _exception1: @@ -1889,7 +1908,7 @@ void cliConnCb(uv_connect_t* req, int status) { return cliSendBatch_shareConn(pConn); } - return cliSend(pConn); + (void)cliSend(pConn); } static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code) { @@ -1950,7 +1969,7 @@ static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { if (!transQueuePush(&conn->reqs, pReq)) { return; } - cliSend(conn); + (void)cliSend(conn); } else { tError("%s conn %p already released", CONN_GET_INST_LABEL(conn), conn); destroyReq(pReq); @@ -2211,7 +2230,7 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { if (code == TSDB_CODE_RPC_MAX_SESSIONS) { TAOS_CHECK_GOTO(code, &lino, _exception); } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { - // do nothing, notifyCb + // do nothing, notiy return; } else { code = cliSendReq(pConn, pReq); @@ -3526,6 +3545,7 @@ _RETURN1: pReq->pCont = NULL; return code; } + int32_t transCreateSyncMsg(STransMsg* pTransMsg, int64_t* refId) { int32_t code = 0; tsem2_t* sem = taosMemoryCalloc(1, sizeof(tsem2_t)); @@ -3562,6 +3582,7 @@ _EXIT: taosMemoryFree(pSyncMsg); return code; } + int32_t transSendRecvWithTimeout(void* pInstRef, SEpSet* pEpSet, STransMsg* pReq, STransMsg* pRsp, int8_t* epUpdated, int32_t timeoutMs) { int32_t code = 0; From c2cccbcf40f35cd21e3a4f99894d05ea118762c3 Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 28 Aug 2024 01:01:59 +0000 Subject: [PATCH 040/240] refactor transport --- source/libs/transport/src/transCli.c | 292 +++++++++++++++------------ 1 file changed, 162 insertions(+), 130 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 9a0f5fa450..4c0a5ec5f3 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -162,7 +162,7 @@ static SCliConn* getConnFromPool(SCliThrd* thread, char* key, bool* exceed); static void addConnToPool(void* pool, SCliConn* conn); static void doCloseIdleConn(void* param); static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); -static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn); +static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int port); static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port); // register conn timer @@ -195,12 +195,11 @@ static int32_t allocConnRef(SCliConn* conn, bool update); static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); void cliResetConnTimer(SCliConn* conn); -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 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, SCliReq** pReq); @@ -413,6 +412,20 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { return false; } +int32_t cliGetTimerFrom(SCliThrd* pThrd, SCliConn* pConn) { + 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) { + return TSDB_CODE_OUT_OF_MEMORY; + } + tDebug("no available timer, create a timer %p", timer); + (void)uv_timer_init(pThrd->loop, timer); + } + timer->data = pConn; + pConn->timer = timer; + return 0; +} void cliResetConnTimer(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; if (conn->timer) { @@ -837,7 +850,6 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p int32_t code = 0; void* pool = pThrd->pool; STrans* pInst = pThrd->pInst; - // size_t klen = strlen(key); SConnList* plist = NULL; code = getOrCreateMsgList(pThrd, key, &plist); @@ -1163,31 +1175,35 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) { + int32_t code = 0; SCliConn* pConn = NULL; + char* ip = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); + int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); - int32_t code = cliCreateConn(pThrd, &pConn); - if (code != 0) { - return code; - } - - char addr[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); - - pConn->dstAddr = taosStrdup(addr); - code = addConnToHeapCache(pThrd->connHeapCache, pConn); + TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); + TAOS_CHECK_GOTO(addConnToHeapCache(pThrd->connHeapCache, pConn), NULL, _exception); transQueuePush(&pConn->reqs, pReq); - return cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + + return cliDoConn(pThrd, pConn, ip, port); +_exception: + // free conn + return code; } -static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { +static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int32_t port) { int32_t code = 0; + int32_t lino = 0; SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); if (conn == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _failed); } + char addr[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(addr, ip, port); + conn->dstAddr = taosStrdup(addr); + transReqQueueInit(&conn->wreqQueue); QUEUE_INIT(&conn->q); conn->hostThrd = pThrd; @@ -1215,6 +1231,8 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); + TAOS_CHECK_GOTO(cliGetTimerFrom(pThrd, conn), &lino, _failed); + // read/write stream handle conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); if (conn->stream == NULL) { @@ -1240,6 +1258,7 @@ _failed: (void)transDestroyBuffer(&conn->readBuf); transQueueDestroy(&conn->reqs); } + tError("failed to create conn, code:%d", code); taosMemoryFree(conn); return code; } @@ -1412,7 +1431,6 @@ void cliSendBatch_shareConn(SCliConn* pConn) { if (size == 0) { tError("%s conn %p not msg to send", pInst->label, pConn); ASSERT(0); - // cliHandleExcept(pConn); return; } uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); @@ -1657,8 +1675,9 @@ static void cliDestroyBatch(SCliBatch* pBatch) { } static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { - int32_t lino = 0; - STrans* pInst = pThrd->pInst; + int32_t lino = 0; + STrans* pInst = pThrd->pInst; + uint32_t ipaddr; int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, ip, &ipaddr); if (code != 0) { @@ -1688,25 +1707,11 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception); return code; } - 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, _exception); - } - - tDebug("no available timer, create a timer %p", timer); - (void)uv_timer_init(pThrd->loop, timer); - } - timer->data = conn; - conn->timer = timer; ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { - // cliResetConnTimer(conn); - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, -1); - return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + tError("failed connect to %s, reason:%s", conn->dstAddr, uv_err_name(ret)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception); } ret = uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); @@ -1747,7 +1752,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { return; } if (conn == NULL) { - code = cliCreateConn(pThrd, &conn); + code = cliCreateConn(pThrd, &conn, pList->ip, pList->port); if (code != 0) { tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d, reason:%s", pInst->label, pBatch->wLen, pBatch->batchSize, pInst->connLimitNum, tstrerror(code)); @@ -1757,7 +1762,13 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { conn->pBatch = pBatch; conn->dstAddr = taosStrdup(pList->dst); - (void)cliDoConn(pThrd, conn, pList->ip, pList->port); + if (conn->dstAddr == NULL) { + tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d, reason:%s", pInst->label, + pBatch->wLen, pBatch->batchSize, pInst->connLimitNum, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + cliDestroyBatch(pBatch); + return; + } + code = cliDoConn(pThrd, conn, pList->ip, pList->port); } conn->pBatch = pBatch; @@ -1826,6 +1837,25 @@ static void cliHandleFastFail(SCliConn* pConn, int status) { cliHandleExcept(pConn, status); } +int32_t cliConnSetSockInfo(SCliConn* pConn) { + struct sockaddr peername, sockname; + int addrlen = sizeof(peername); + + (void)uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen); + (void)transSockInfo2Str(&peername, pConn->dst); + + addrlen = sizeof(sockname); + (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; + + pConn->clientIp = addr.sin_addr.s_addr; + pConn->serverIp = saddr.sin_addr.s_addr; + + return 0; +}; void cliConnCb(uv_connect_t* req, int status) { SCliConn* pConn = req->data; SCliThrd* pThrd = pConn->hostThrd; @@ -1840,29 +1870,22 @@ void cliConnCb(uv_connect_t* req, int status) { STUB_RAND_NETWORK_ERR(status); if (status != 0) { - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, pConn->dstAddr); - if (timeout == false) { - cliHandleFastFail(pConn, status); - } else if (timeout == true) { - // already deal by timeout - } - return; + tDebug("%s conn %p failed to connect to %s, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, + uv_strerror(status)); + // handle err + // 1. update statis + // 2. notifyCb or retry + // 3. clear conn and + // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, pConn->dstAddr); + // if (timeout == false) { + // cliHandleFastFail(pConn, status); + // } else if (timeout == true) { + // // already deal by timeout + // } + // return; } - struct sockaddr peername, sockname; - int addrlen = sizeof(peername); - (void)uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen); - (void)transSockInfo2Str(&peername, pConn->dst); - - addrlen = sizeof(sockname); - (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; - - pConn->clientIp = addr.sin_addr.s_addr; - pConn->serverIp = saddr.sin_addr.s_addr; + cliConnSetSockInfo(pConn); tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); if (pConn->pBatch != NULL) { @@ -1906,6 +1929,7 @@ static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq) { } pThrd->stopMsg = NULL; pThrd->quit = true; + tDebug("cli work thread %p start to quit", pThrd); destroyReq(pReq); @@ -2147,8 +2171,10 @@ void cliHandleReq__shareConn(SCliThrd* pThrd, SCliReq* pReq) { STraceId* trace = &pReq->msg.info.traceId; STrans* pInst = pThrd->pInst; - char addr[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(addr, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + char addr[TSDB_FQDN_LEN + 64] = {0}; + char* ip = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); + int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); + CONN_CONSTRUCT_HASH_KEY(addr, ip, port); SCliConn* pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); if (pConn == NULL) { @@ -2167,13 +2193,13 @@ void cliHandleReq__shareConn(SCliThrd* pThrd, SCliReq* pReq) { return; } - code = cliCreateConn(pThrd, &pConn); - pConn->dstAddr = taosStrdup(addr); - code = addConnToHeapCache(pThrd->connHeapCache, pConn); + TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); + + TAOS_CHECK_GOTO(addConnToHeapCache(pThrd->connHeapCache, pConn), NULL, _exception); transQueuePush(&pConn->reqs, pReq); - cliDoConn(pThrd, pConn, EPSET_GET_INUSE_IP(&pReq->ctx->epSet), EPSET_GET_INUSE_PORT(&pReq->ctx->epSet)); + code = cliDoConn(pThrd, pConn, ip, port); _exception: resp.code = code; @@ -2248,9 +2274,68 @@ SCliBatch* cliGetHeadFromList(SCliBatchList* pList) { SCliBatch* batch = QUEUE_DATA(hr, SCliBatch, listq); return batch; } +static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliReq* pReq); + +static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, uint32_t port); + +static void destroyBatchList(SCliBatchList* pList); static void cliBuildBatch(SCliReq* pReq, queue* h, SCliThrd* pThrd) { + int32_t code = 0; STrans* pInst = pThrd->pInst; SReqCtx* pCtx = pReq->ctx; + + char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet); + uint32_t port = EPSET_GET_INUSE_PORT(&pCtx->epSet); + char key[TSDB_FQDN_LEN + 64] = {0}; + CONN_CONSTRUCT_HASH_KEY(key, ip, port); + size_t klen = strlen(key); + SCliBatchList** ppBatchList = taosHashGet(pThrd->batchCache, key, klen); + if (ppBatchList == NULL || *ppBatchList == NULL) { + SCliBatchList* pBatchList = NULL; + code = createBatchList(&pBatchList, key, ip, port); + if (code != 0) { + destroyReq(pReq); + return; + } + + pBatchList->batchLenLimit = pInst->batchSize; + + SCliBatch* pBatch = NULL; + code = createBatch(&pBatch, pBatchList, pReq); + if (code != 0) { + destroyBatchList(pBatchList); + destroyReq(pReq); + return; + } + + code = taosHashPut(pThrd->batchCache, key, klen, &pBatchList, sizeof(void*)); + if (code != 0) { + destroyBatchList(pBatchList); + } + } else { + if (QUEUE_IS_EMPTY(&(*ppBatchList)->wq)) { + SCliBatch* pBatch = NULL; + code = createBatch(&pBatch, *ppBatchList, pReq); + if (code != 0) { + destroyReq(pReq); + cliDestroyBatch(pBatch); + } + } else { + queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); + SCliBatch* pBatch = QUEUE_DATA(hdr, SCliBatch, listq); + if ((pBatch->batchSize + pReq->msg.contLen) < (*ppBatchList)->batchLenLimit) { + QUEUE_PUSH(&pBatch->wq, h); + pBatch->batchSize += pReq->msg.contLen; + pBatch->wLen += 1; + } else { + SCliBatch* tBatch = NULL; + code = createBatch(&tBatch, *ppBatchList, pReq); + if (code != 0) { + destroyReq(pReq); + } + } + } + } return; } static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, uint32_t port) { @@ -2329,64 +2414,6 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { cliBuildBatch(pReq, h, pThrd); continue; } - - if (pReq->type == Normal && REQUEST_NO_RESP(&pReq->msg)) { - SReqCtx* pCtx = pReq->ctx; - - char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet); - uint32_t port = EPSET_GET_INUSE_PORT(&pCtx->epSet); - char key[TSDB_FQDN_LEN + 64] = {0}; - CONN_CONSTRUCT_HASH_KEY(key, ip, port); - size_t klen = strlen(key); - SCliBatchList** ppBatchList = taosHashGet(pThrd->batchCache, key, klen); - if (ppBatchList == NULL || *ppBatchList == NULL) { - SCliBatchList* pBatchList = NULL; - code = createBatchList(&pBatchList, key, ip, port); - if (code != 0) { - destroyReq(pReq); - continue; - } - - pBatchList->batchLenLimit = pInst->batchSize; - - SCliBatch* pBatch = NULL; - code = createBatch(&pBatch, pBatchList, pReq); - if (code != 0) { - destroyBatchList(pBatchList); - destroyReq(pReq); - continue; - } - - code = taosHashPut(pThrd->batchCache, key, klen, &pBatchList, sizeof(void*)); - if (code != 0) { - destroyBatchList(pBatchList); - } - } else { - if (QUEUE_IS_EMPTY(&(*ppBatchList)->wq)) { - SCliBatch* pBatch = NULL; - code = createBatch(&pBatch, *ppBatchList, pReq); - if (code != 0) { - destroyReq(pReq); - cliDestroyBatch(pBatch); - } - } else { - queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); - SCliBatch* pBatch = QUEUE_DATA(hdr, SCliBatch, listq); - if ((pBatch->batchSize + pReq->msg.contLen) < (*ppBatchList)->batchLenLimit) { - QUEUE_PUSH(&pBatch->wq, h); - pBatch->batchSize += pReq->msg.contLen; - pBatch->wLen += 1; - } else { - SCliBatch* tBatch = NULL; - code = createBatch(&tBatch, *ppBatchList, pReq); - if (code != 0) { - destroyReq(pReq); - } - } - } - } - continue; - } (*cliAsyncHandle[pReq->type])(pThrd, pReq); count++; } @@ -2896,6 +2923,10 @@ FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { int32_t len = pResp->contLen - tlen; if (len != 0) { buf = rpcMallocCont(len); + if (buf == NULL) { + pResp->code = TSDB_CODE_OUT_OF_MEMORY; + return false; + } // TODO: check buf memcpy(buf, (char*)pResp->pCont + tlen, len); } @@ -2909,6 +2940,7 @@ FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { epsetAssign(dst, &epset); return true; } + bool cliResetEpset(SReqCtx* pCtx, STransMsg* pResp, bool hasEpSet) { bool noDelay = true; if (hasEpSet == false) { @@ -3749,7 +3781,7 @@ _exception: return code; } -static int32_t getOrCreateHeapIfNotExist(SHashObj* pConnHeapCache, char* key, SHeap** pHeap) { +static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHeap) { int32_t code = 0; size_t klen = strlen(key); @@ -3780,7 +3812,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int code = 0; SHeap* pHeap = NULL; SCliConn* pConn = NULL; - code = getOrCreateHeapIfNotExist(pConnHeapCache, key, &pHeap); + code = getOrCreateHeap(pConnHeapCache, key, &pHeap); if (code != 0) { tDebug("failed to get conn heap from cache for key:%s", key); return NULL; @@ -3795,7 +3827,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { SHeap* p = NULL; - int32_t code = getOrCreateHeapIfNotExist(pConnHeapCacahe, pConn->dstAddr, &p); + int32_t code = getOrCreateHeap(pConnHeapCacahe, pConn->dstAddr, &p); if (code != 0) { return code; } From 6554e01641e7294bea82a85c5d2d49111c73901d Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Wed, 28 Aug 2024 11:45:03 +0000 Subject: [PATCH 041/240] check return code --- source/libs/transport/src/transCli.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 11791fac00..c23f7b781f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -87,6 +87,9 @@ typedef struct SCliConn { char src[32]; char dst[32]; + char* ipStr; + int32_t port; + int64_t refId; int32_t seq; int32_t shareCnt; @@ -165,7 +168,7 @@ static void addConnToPool(void* pool, SCliConn* conn); static void doCloseIdleConn(void* param); static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int port); -static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port); +static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn); // register conn timer static void cliConnTimeout(uv_timer_t* handle); @@ -1216,7 +1219,7 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) transQueuePush(&pConn->reqs, pReq); - return cliDoConn(pThrd, pConn, ip, port); + return cliDoConn(pThrd, pConn); _exception: // free conn return code; @@ -1234,6 +1237,8 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int char addr[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(addr, ip, port); conn->dstAddr = taosStrdup(addr); + conn->ipStr = taosStrdup(ip); + conn->port = port; transReqQueueInit(&conn->wreqQueue); QUEUE_INIT(&conn->q); @@ -1679,12 +1684,12 @@ static void cliDestroyBatch(SCliBatch* pBatch) { taosMemoryFree(pBatch); } -static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { +static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { int32_t lino = 0; STrans* pInst = pThrd->pInst; uint32_t ipaddr; - int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, ip, &ipaddr); + int32_t code = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, conn->ipStr, &ipaddr); if (code != 0) { TAOS_CHECK_GOTO(code, &lino, _exception1); } @@ -1692,7 +1697,7 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) { struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_addr.s_addr = ipaddr; - addr.sin_port = (uint16_t)htons(port); + addr.sin_port = (uint16_t)htons(conn->port); tTrace("%s conn %p try to connect to %s", pInst->label, conn, conn->dstAddr); @@ -1777,14 +1782,11 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { } conn->pBatch = pBatch; - conn->dstAddr = taosStrdup(pList->dst); - if (conn->dstAddr == NULL) { - tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d, reason:%s", pInst->label, - pBatch->wLen, pBatch->batchSize, pInst->connLimitNum, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - cliDestroyBatch(pBatch); - return; + code = cliDoConn(pThrd, conn); + if (code != 0) { + } - code = cliDoConn(pThrd, conn, pList->ip, pList->port); + return; } conn->pBatch = pBatch; @@ -2215,7 +2217,7 @@ void cliHandleReq__shareConn(SCliThrd* pThrd, SCliReq* pReq) { transQueuePush(&pConn->reqs, pReq); - code = cliDoConn(pThrd, pConn, ip, port); + code = cliDoConn(pThrd, pConn); _exception: resp.code = code; From a45b9b2d6f5da8d51a8a231128a3f4e3710d161b Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 29 Aug 2024 01:20:40 +0000 Subject: [PATCH 042/240] refactor transport --- source/libs/transport/src/transCli.c | 121 +++++++++++++++++++++------ 1 file changed, 94 insertions(+), 27 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c23f7b781f..448dd7796f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -428,7 +428,7 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { return false; } -int32_t cliGetTimerFrom(SCliThrd* pThrd, SCliConn* pConn) { +int32_t cliGetConnTimer(SCliThrd* pThrd, SCliConn* pConn) { 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)); @@ -482,7 +482,7 @@ bool cliShouldAddConnToPool(SCliConn* conn) { void cliHandleResp_shareConn(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - cliResetConnTimer(conn); + // cliResetConnTimer(conn); STransMsgHead* pHead = NULL; int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 1); @@ -498,6 +498,80 @@ void cliHandleResp_shareConn(SCliConn* conn) { pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); + STransMsg resp = {0}; + resp.contLen = transContLenFromMsg(pHead->msgLen); + resp.pCont = transContFromHead((char*)pHead); + resp.code = pHead->code; + resp.msgType = pHead->msgType; + resp.info.ahandle = NULL; + resp.info.traceId = pHead->traceId; + resp.info.hasEpSet = pHead->hasEpSet; + resp.info.cliVer = htonl(pHead->compatibilityVer); + + SCliReq* pReq = cliFindReqBySeq(conn, pHead->seqNum); + pReq->seq = 0; + + SReqCtx* pCtx = pReq->ctx; + resp.info.ahandle = pCtx ? pCtx->ahandle : NULL; + STraceId* trace = &resp.info.traceId; + + int32_t ret = cliNotifyCb(conn, pReq, &resp); + if (ret != 0) { + return; + } else { + destroyReq(pReq); + } +} + +int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { + int32_t code = 0; + for (int i = 0; i < transQueueSize(&conn->reqs); i++) { + SCliReq* p = transQueueGet(&conn->reqs, i); + if (p->seq == seq) { + transQueueRm(&conn->reqs, i); + *pReq = p; + return 0; + } + } + return TSDB_CODE_OUT_OF_RANGE; +} +void cliHandleResp2(SCliConn* conn) { + int32_t code = 0; + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + + cliResetConnTimer(conn); + if (pInst->shareConn) { + return cliHandleResp_shareConn(conn); + } + + STransMsgHead* pHead = NULL; + + // int8_t resetBuf = conn->status == ConnAcquire ? 0 : 1; + int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 0); + if (msgLen < 0) { + taosMemoryFree(pHead); + tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); + // TODO: notify cb + pThrd->notifyExceptCb(pThrd, NULL, NULL); + return; + } + + if ((code = transDecompressMsg((char**)&pHead, msgLen)) < 0) { + tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); + // TODO: notify cb + } + + SCliReq* pReq = NULL; + int32_t seq = pHead->seqNum; + code = cliGetReqBySeq(conn, seq, &pReq); + pHead->code = htonl(pHead->code); + pHead->msgLen = htonl(pHead->msgLen); + // TODO handle release req + // if (cliRecvReleaseReq(conn, pHead)) { + // return; + // } + STransMsg transMsg = {0}; transMsg.contLen = transContLenFromMsg(pHead->msgLen); transMsg.pCont = transContFromHead((char*)pHead); @@ -508,29 +582,21 @@ void cliHandleResp_shareConn(SCliConn* conn) { transMsg.info.hasEpSet = pHead->hasEpSet; transMsg.info.cliVer = htonl(pHead->compatibilityVer); - SCliReq* pReq = cliFindReqBySeq(conn, pHead->seqNum); - pReq->seq = 0; - - SReqCtx* pCtx = pReq->ctx; - transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; - STraceId* trace = &transMsg.info.traceId; - - int32_t ret = cliNotifyCb(conn, pReq, &transMsg); - if (ret != 0) { - return; - } else { - destroyReq(pReq); + if (code != 0) { + tDebug("%s conn %p recv invalid packet, seq %d not found", CONN_GET_INST_LABEL(conn), conn, seq); } + + return; } void cliHandleResp(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; + cliResetConnTimer(conn); if (pInst->shareConn) { return cliHandleResp_shareConn(conn); } - cliResetConnTimer(conn); STransMsgHead* pHead = NULL; @@ -540,6 +606,7 @@ void cliHandleResp(SCliConn* conn) { taosMemoryFree(pHead); tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb + pThrd->notifyExceptCb(pThrd, NULL, NULL); return; } @@ -1267,7 +1334,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); - TAOS_CHECK_GOTO(cliGetTimerFrom(pThrd, conn), &lino, _failed); + TAOS_CHECK_GOTO(cliGetConnTimer(pThrd, conn), &lino, _failed); // read/write stream handle conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); @@ -1379,25 +1446,25 @@ static void cliSendCb(uv_write_t* req, int status) { } static void cliHandleBatch_shareConnExcept(SCliConn* conn) { - int32_t code = -1; + int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; while (!transQueueEmpty(&conn->reqs)) { SCliReq* pReq = transQueuePop(&conn->reqs); - ASSERT(pReq->type != Release); - ASSERT(REQUEST_NO_RESP(&pReq->msg) == 0); + // ASSERT(pReq->type != Release); + // ASSERT(REQUEST_NO_RESP(&pReq->msg) == 0); SReqCtx* pCtx = pReq ? pReq->ctx : NULL; - STransMsg transMsg = {0}; - transMsg.code = code == -1 ? (conn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; - transMsg.msgType = pReq ? pReq->msg.msgType + 1 : 0; - transMsg.info.ahandle = NULL; - transMsg.info.cliVer = pInst->compatibilityVer; - transMsg.info.ahandle = pCtx->ahandle; + STransMsg resp = {0}; + resp.code = code == -1 ? (conn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; + resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; + resp.info.ahandle = NULL; + resp.info.cliVer = pInst->compatibilityVer; + resp.info.ahandle = pCtx->ahandle; pReq->seq = 0; - code = cliNotifyCb(conn, pReq, &transMsg); + code = cliNotifyCb(conn, pReq, &resp); if (code != 0) { continue; } else { @@ -1484,6 +1551,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pCliMsg->sent = 1; pCliMsg->seq = pHead->seqNum; } + uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); req->data = pConn; pConn->shareCnt += 1; @@ -1784,7 +1852,6 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { conn->pBatch = pBatch; code = cliDoConn(pThrd, conn); if (code != 0) { - } return; } From 7d81d4f18e6b8f1125a21bf971e2846f15f185cf Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Thu, 29 Aug 2024 03:24:02 +0000 Subject: [PATCH 043/240] refactor transport --- source/libs/transport/src/transCli.c | 75 ++++++++++++++++++---------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 448dd7796f..6afb1fac00 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -535,6 +535,14 @@ int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { } return TSDB_CODE_OUT_OF_RANGE; } + +int32_t cliMayRecycleConn(SCliConn* conn) { + SCliThrd* pThrd = conn->hostThrd; + if (transQueueSize(&conn->reqs) == 0) { + addConnToPool(pThrd->pool, conn); + } + return 0; +} void cliHandleResp2(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; @@ -560,11 +568,18 @@ void cliHandleResp2(SCliConn* conn) { if ((code = transDecompressMsg((char**)&pHead, msgLen)) < 0) { tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb + return; } SCliReq* pReq = NULL; int32_t seq = pHead->seqNum; code = cliGetReqBySeq(conn, seq, &pReq); + if (code != 0) { + tDebug("%s conn %p recv unexpected packet, reason:%s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + // TODO: notify cb + return; + } + pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); // TODO handle release req @@ -572,20 +587,28 @@ void cliHandleResp2(SCliConn* conn) { // return; // } - STransMsg transMsg = {0}; - transMsg.contLen = transContLenFromMsg(pHead->msgLen); - transMsg.pCont = transContFromHead((char*)pHead); - transMsg.code = pHead->code; - transMsg.msgType = pHead->msgType; - transMsg.info.ahandle = NULL; - transMsg.info.traceId = pHead->traceId; - transMsg.info.hasEpSet = pHead->hasEpSet; - transMsg.info.cliVer = htonl(pHead->compatibilityVer); + STransMsg resp = {0}; + resp.contLen = transContLenFromMsg(pHead->msgLen); + resp.pCont = transContFromHead((char*)pHead); + resp.code = pHead->code; + resp.msgType = pHead->msgType; + resp.info.ahandle = NULL; + resp.info.traceId = pHead->traceId; + resp.info.hasEpSet = pHead->hasEpSet; + resp.info.cliVer = htonl(pHead->compatibilityVer); + resp.info.ahandle = pReq->ctx ? pReq->ctx->ahandle : NULL; if (code != 0) { tDebug("%s conn %p recv invalid packet, seq %d not found", CONN_GET_INST_LABEL(conn), conn, seq); } - + code = cliNotifyCb(conn, pReq, &resp); + if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + STraceId* trace = &resp.info.traceId; + tGWarn("%s msg need retry", CONN_GET_INST_LABEL(conn)); + // retry, notify + } else { + } + (void)cliMayRecycleConn(conn); return; } void cliHandleResp(SCliConn* conn) { @@ -594,9 +617,9 @@ void cliHandleResp(SCliConn* conn) { STrans* pInst = pThrd->pInst; cliResetConnTimer(conn); - if (pInst->shareConn) { - return cliHandleResp_shareConn(conn); - } + // if (pInst->shareConn) { + // return cliHandleResp_shareConn(conn); + // } STransMsgHead* pHead = NULL; @@ -2715,6 +2738,9 @@ int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { int32_t notfiyCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { // impl later + SCliThrd* pThrd = thrd; + STrans* pInst = pThrd->pInst; + return 0; } @@ -3176,7 +3202,7 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); noDelay = cliResetEpset(pCtx, pResp, false); transFreeMsg(pResp->pCont); - transUnrefCliHandle(pConn); + // transUnrefCliHandle(pConn); } else if (code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_INTERNAL_ERROR || code == TSDB_CODE_SYN_PROPOSE_NOT_READY || code == TSDB_CODE_VND_STOPPED || code == TSDB_CODE_MNODE_NOT_FOUND || code == TSDB_CODE_APP_IS_STARTING || @@ -3184,16 +3210,16 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { tTrace("code str %s, contlen:%d 1", tstrerror(code), pResp->contLen); noDelay = cliResetEpset(pCtx, pResp, true); transFreeMsg(pResp->pCont); - addConnToPool(pThrd->pool, pConn); + // addConnToPool(pThrd->pool, pConn); } else if (code == TSDB_CODE_SYN_RESTORING) { tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); noDelay = cliResetEpset(pCtx, pResp, true); - addConnToPool(pThrd->pool, pConn); + // addConnToPool(pThrd->pool, pConn); transFreeMsg(pResp->pCont); } else { tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); noDelay = cliResetEpset(pCtx, pResp, false); - addConnToPool(pThrd->pool, pConn); + // addConnToPool(pThrd->pool, pConn); transFreeMsg(pResp->pCont); } if (code != TSDB_CODE_RPC_BROKEN_LINK && code != TSDB_CODE_RPC_NETWORK_UNAVAIL && code != TSDB_CODE_SUCCESS) { @@ -3283,15 +3309,14 @@ int32_t cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - if (pReq == NULL || pReq->ctx == NULL) { - tTrace("%s conn %p handle resp", pInst->label, pConn); - pInst->cfp(pInst->parent, pResp, NULL); - return 0; - } + // if (pReq == NULL || pReq->ctx == NULL) { + // tTrace("%s conn %p handle resp", pInst->label, pConn); + // pInst->cfp(pInst->parent, pResp, NULL); + // return 0; + // } - bool retry = cliMayRetry(pConn, pReq, pResp); - if (retry == true) { - return -1; + if (cliMayRetry(pConn, pReq, pResp)) { + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } cliMayResetRespCode(pReq, pResp); From 51f3ff3207b1c87c4f9613604661bc4d26df1c37 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 31 Aug 2024 09:00:03 +0800 Subject: [PATCH 044/240] fix unit test --- source/libs/transport/src/transCli.c | 114 ++++++++------------------- 1 file changed, 34 insertions(+), 80 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 6afb1fac00..ceba448613 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -454,6 +454,7 @@ void cliResetConnTimer(SCliConn* conn) { conn->timer = NULL; } } + void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } SCliReq* cliFindReqBySeq(SCliConn* conn, int32_t seq) { @@ -479,49 +480,6 @@ bool cliShouldAddConnToPool(SCliConn* conn) { return empty; } -void cliHandleResp_shareConn(SCliConn* conn) { - SCliThrd* pThrd = conn->hostThrd; - STrans* pInst = pThrd->pInst; - // cliResetConnTimer(conn); - - STransMsgHead* pHead = NULL; - int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 1); - - if (msgLen <= 0) { - taosMemoryFree(pHead); - tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); - return; - } - if (transDecompressMsg((char**)&pHead, msgLen) < 0) { - tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); - } - pHead->code = htonl(pHead->code); - pHead->msgLen = htonl(pHead->msgLen); - - STransMsg resp = {0}; - resp.contLen = transContLenFromMsg(pHead->msgLen); - resp.pCont = transContFromHead((char*)pHead); - resp.code = pHead->code; - resp.msgType = pHead->msgType; - resp.info.ahandle = NULL; - resp.info.traceId = pHead->traceId; - resp.info.hasEpSet = pHead->hasEpSet; - resp.info.cliVer = htonl(pHead->compatibilityVer); - - SCliReq* pReq = cliFindReqBySeq(conn, pHead->seqNum); - pReq->seq = 0; - - SReqCtx* pCtx = pReq->ctx; - resp.info.ahandle = pCtx ? pCtx->ahandle : NULL; - STraceId* trace = &resp.info.traceId; - - int32_t ret = cliNotifyCb(conn, pReq, &resp); - if (ret != 0) { - return; - } else { - destroyReq(pReq); - } -} int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { int32_t code = 0; @@ -536,27 +494,36 @@ int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { return TSDB_CODE_OUT_OF_RANGE; } -int32_t cliMayRecycleConn(SCliConn* conn) { +int8_t cliMayRecycleConn(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; if (transQueueSize(&conn->reqs) == 0) { addConnToPool(pThrd->pool, conn); + return 1; } return 0; } + +int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHead) { + pResp->contLen = transContLenFromMsg(pHead->msgLen); + pResp->pCont = transContFromHead((char*)pHead); + pResp->code = pReq->msg.code; + pResp->msgType = pReq->msg.msgType; + pResp->info.ahandle = pReq->ctx ? pReq->ctx->ahandle : NULL; + pResp->info.traceId = pReq->msg.info.traceId; + pResp->info.hasEpSet = pReq->msg.info.hasEpSet; + pResp->info.cliVer = pReq->msg.info.cliVer; + return 0; +} void cliHandleResp2(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; cliResetConnTimer(conn); - if (pInst->shareConn) { - return cliHandleResp_shareConn(conn); - } - - STransMsgHead* pHead = NULL; // int8_t resetBuf = conn->status == ConnAcquire ? 0 : 1; - int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 0); + STransMsgHead* pHead = NULL; + int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 0); if (msgLen < 0) { taosMemoryFree(pHead); tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); @@ -588,38 +555,31 @@ void cliHandleResp2(SCliConn* conn) { // } STransMsg resp = {0}; - resp.contLen = transContLenFromMsg(pHead->msgLen); - resp.pCont = transContFromHead((char*)pHead); - resp.code = pHead->code; - resp.msgType = pHead->msgType; - resp.info.ahandle = NULL; - resp.info.traceId = pHead->traceId; - resp.info.hasEpSet = pHead->hasEpSet; - resp.info.cliVer = htonl(pHead->compatibilityVer); - resp.info.ahandle = pReq->ctx ? pReq->ctx->ahandle : NULL; - + code = cliBuildRespFromCont(pReq, &resp, pHead); if (code != 0) { tDebug("%s conn %p recv invalid packet, seq %d not found", CONN_GET_INST_LABEL(conn), conn, seq); } + code = cliNotifyCb(conn, pReq, &resp); if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { STraceId* trace = &resp.info.traceId; tGWarn("%s msg need retry", CONN_GET_INST_LABEL(conn)); // retry, notify } else { + destroyReq(pReq); } - (void)cliMayRecycleConn(conn); - return; + if (cliMayRecycleConn(conn)) { + return; + } + (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } + void cliHandleResp(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; cliResetConnTimer(conn); - // if (pInst->shareConn) { - // return cliHandleResp_shareConn(conn); - // } STransMsgHead* pHead = NULL; @@ -1686,7 +1646,6 @@ int32_t cliSend(SCliConn* pConn) { STrans* pInst = pThrd->pInst; SCliReq* pCliReq = NULL; int32_t code = cliConnFindToSendMsg(pConn, &pCliReq); - if (code != 0) { return code; } @@ -1699,7 +1658,6 @@ int32_t cliSend(SCliConn* pConn) { if (pReq->pCont == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - tDebug("malloc memory: %p", pReq->pCont); pReq->contLen = 0; } @@ -1719,12 +1677,10 @@ int32_t cliSend(SCliConn* pConn) { pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->version = TRANS_VER; pHead->compatibilityVer = htonl(pInst->compatibilityVer); + pHead->seqNum = pConn->seq++; } - pHead->timestamp = taosHton64(taosGetTimestampUs()); - if (pHead->persist == 1) { - CONN_SET_PERSIST_BY_APP(pConn); - } + pHead->timestamp = taosHton64(taosGetTimestampUs()); STraceId* trace = &pReq->info.traceId; @@ -1741,24 +1697,22 @@ int32_t cliSend(SCliConn* pConn) { TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, msgLen); uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); - uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); - if (req == NULL) { - tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - cliHandleExcept(pConn, -1); - return TSDB_CODE_OUT_OF_MEMORY; + uv_write_t* aReq = transReqQueuePush(&pConn->wreqQueue); + if (aReq == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); } pCliReq->sent = 1; - int status = uv_write(req, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); + int status = uv_write(aReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); if (status != 0) { tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), uv_err_name(status)); - cliHandleExcept(pConn, -1); - return TSDB_CODE_THIRDPARTY_ERROR; + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _exception); } return TSDB_CODE_RPC_ASYNC_IN_PROCESS; +_exception: + return code; } static void cliDestroyBatch(SCliBatch* pBatch) { From ea2eacadd381ec83184a77df5ee43df9d6c0e1cc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 3 Sep 2024 14:46:56 +0800 Subject: [PATCH 045/240] fix mem leak --- source/libs/transport/src/transCli.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index ceba448613..edcf933aab 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2621,6 +2621,7 @@ static void* cliWorkThread(void* arg) { SCliThrd* pThrd = (SCliThrd*)arg; pThrd->pid = taosGetSelfPthreadId(); + tsEnableRandErr = true; (void)strtolower(threadName, pThrd->pInst->label); setThreadName(threadName); From 603de3976c68495f9c71629236e53c69dc513984 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 3 Sep 2024 19:40:13 +0800 Subject: [PATCH 046/240] refactor transport --- include/libs/transport/trpc.h | 5 +- source/libs/transport/src/transCli.c | 683 ++++++++++++++------------- source/libs/transport/src/transSvr.c | 12 +- 3 files changed, 356 insertions(+), 344 deletions(-) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 486a5e35c3..cc9d789430 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -63,6 +63,7 @@ typedef struct SRpcHandleInfo { int8_t forbiddenIp; int8_t notFreeAhandle; int8_t compressed; + int32_t seqNum; } SRpcHandleInfo; typedef struct SRpcMsg { @@ -125,8 +126,8 @@ typedef struct SRpcInit { int32_t timeToGetConn; int8_t supportBatch; // 0: no batch, 1. batch int32_t batchSize; - int8_t shareConn; // 0: no share, 1. share - int8_t notWaitAvaliableConn; // 1: wait to get, 0: no wait + int8_t shareConn; // 0: no share, 1. share + int8_t notWaitAvaliableConn; // 1: wait to get, 0: no wait void *parent; } SRpcInit; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index edcf933aab..a3cd6eacd0 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -169,7 +169,9 @@ static void doCloseIdleConn(void* param); static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int port); static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn); - +static void cliSendBatch_shareConnCb(uv_write_t* req, int status); +void cliSendBatch_shareConn(SCliConn* pConn); +int32_t cliSend2(SCliConn* conn); // register conn timer static void cliConnTimeout(uv_timer_t* handle); // register timer for read @@ -236,9 +238,9 @@ static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq); static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq); static void cliHandleFreeById(SCliThrd* pThrd, SCliReq* pReq); -static void cliDealReq(queue* h, SCliThrd* pThrd); -static void cliBatchDealReq(queue* h, SCliThrd* pThrd); -static void (*cliDealFunc[])(queue* h, SCliThrd* pThrd) = {cliDealReq, cliBatchDealReq}; +static void cliDoReq(queue* h, SCliThrd* pThrd); +static void cliDoBatchReq(queue* h, SCliThrd* pThrd); +static void (*cliDealFunc[])(queue* h, SCliThrd* pThrd) = {cliDoReq, cliDoBatchReq}; static void (*cliAsyncHandle[])(SCliThrd* pThrd, SCliReq* pReq) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL, cliHandleUpdate, cliHandleFreeById}; @@ -392,7 +394,7 @@ bool cliMaySendCachedMsg(SCliConn* conn) { if (!transQueueEmpty(&conn->reqs)) { SCliReq* pCliMsg = NULL; CONN_GET_NEXT_SENDMSG(conn); - (void)cliSend(conn); + (void)cliSend2(conn); return true; } return false; @@ -419,7 +421,7 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { (void)transQueuePush(&conn->reqs, t); tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); (void)transReleaseExHandle(transGetRefMgt(), refId); - (void)cliSend(conn); + (void)cliSend2(conn); return true; } taosWUnLockLatch(&exh->latch); @@ -457,20 +459,6 @@ void cliResetConnTimer(SCliConn* conn) { void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } -SCliReq* cliFindReqBySeq(SCliConn* conn, int32_t seq) { - SCliReq* pReq = NULL; - for (int i = 0; i < transQueueSize(&conn->reqs); i++) { - pReq = transQueueGet(&conn->reqs, i); - if (pReq->seq == seq) { - transQueueRm(&conn->reqs, i); - break; - } - } - if (pReq == NULL) { - ASSERT(0); - } - return pReq; -} bool cliShouldAddConnToPool(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; bool empty = transQueueEmpty(&conn->reqs); @@ -521,7 +509,6 @@ void cliHandleResp2(SCliConn* conn) { cliResetConnTimer(conn); - // int8_t resetBuf = conn->status == ConnAcquire ? 0 : 1; STransMsgHead* pHead = NULL; int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 0); if (msgLen < 0) { @@ -539,7 +526,7 @@ void cliHandleResp2(SCliConn* conn) { } SCliReq* pReq = NULL; - int32_t seq = pHead->seqNum; + int32_t seq = htonl(pHead->seqNum); code = cliGetReqBySeq(conn, seq, &pReq); if (code != 0) { tDebug("%s conn %p recv unexpected packet, reason:%s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); @@ -574,206 +561,191 @@ void cliHandleResp2(SCliConn* conn) { (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } -void cliHandleResp(SCliConn* conn) { - int32_t code = 0; - SCliThrd* pThrd = conn->hostThrd; - STrans* pInst = pThrd->pInst; +// void cliHandleResp(SCliConn* conn) { +// int32_t code = 0; +// SCliThrd* pThrd = conn->hostThrd; +// STrans* pInst = pThrd->pInst; - cliResetConnTimer(conn); +// cliResetConnTimer(conn); - STransMsgHead* pHead = NULL; +// STransMsgHead* pHead = NULL; - int8_t resetBuf = conn->status == ConnAcquire ? 0 : 1; - int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, resetBuf); - if (msgLen <= 0) { - taosMemoryFree(pHead); - tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); - // TODO: notify cb - pThrd->notifyExceptCb(pThrd, NULL, NULL); - return; - } +// int8_t resetBuf = conn->status == ConnAcquire ? 0 : 1; +// int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, resetBuf); +// if (msgLen <= 0) { +// taosMemoryFree(pHead); +// tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); +// // TODO: notify cb +// pThrd->notifyExceptCb(pThrd, NULL, NULL); +// return; +// } - if (resetBuf == 0) { - tTrace("%s conn %p not reset read buf", transLabel(pInst), conn); - } +// if (resetBuf == 0) { +// tTrace("%s conn %p not reset read buf", transLabel(pInst), conn); +// } - if ((code = transDecompressMsg((char**)&pHead, msgLen)) < 0) { - tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); - // TODO: notify cb - } - pHead->code = htonl(pHead->code); - pHead->msgLen = htonl(pHead->msgLen); - if (cliRecvReleaseReq(conn, pHead)) { - return; - } +// if ((code = transDecompressMsg((char**)&pHead, msgLen)) < 0) { +// tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); +// // TODO: notify cb +// } +// pHead->code = htonl(pHead->code); +// pHead->msgLen = htonl(pHead->msgLen); +// if (cliRecvReleaseReq(conn, pHead)) { +// return; +// } - STransMsg transMsg = {0}; - transMsg.contLen = transContLenFromMsg(pHead->msgLen); - transMsg.pCont = transContFromHead((char*)pHead); - transMsg.code = pHead->code; - transMsg.msgType = pHead->msgType; - transMsg.info.ahandle = NULL; - transMsg.info.traceId = pHead->traceId; - transMsg.info.hasEpSet = pHead->hasEpSet; - transMsg.info.cliVer = htonl(pHead->compatibilityVer); +// STransMsg transMsg = {0}; +// transMsg.contLen = transContLenFromMsg(pHead->msgLen); +// transMsg.pCont = transContFromHead((char*)pHead); +// transMsg.code = pHead->code; +// transMsg.msgType = pHead->msgType; +// transMsg.info.ahandle = NULL; +// transMsg.info.traceId = pHead->traceId; +// transMsg.info.hasEpSet = pHead->hasEpSet; +// transMsg.info.cliVer = htonl(pHead->compatibilityVer); - SCliReq* pReq = NULL; - SReqCtx* pCtx = NULL; - if (CONN_NO_PERSIST_BY_APP(conn)) { - pReq = transQueuePop(&conn->reqs); +// SCliReq* pReq = NULL; +// SReqCtx* pCtx = NULL; +// if (CONN_NO_PERSIST_BY_APP(conn)) { +// pReq = transQueuePop(&conn->reqs); - pCtx = pReq ? pReq->ctx : NULL; - transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; - tDebug("%s conn %p get ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); - } else { - uint64_t ahandle = (uint64_t)pHead->ahandle; - CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); - if (pReq == NULL) { - transMsg.info.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType); - tDebug("%s conn %p construct ahandle %p by %s, persist: 1", CONN_GET_INST_LABEL(conn), conn, - transMsg.info.ahandle, TMSG_INFO(transMsg.msgType)); - if (!CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) { - transMsg.code = TSDB_CODE_RPC_BROKEN_LINK; - transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType)); - tDebug("%s conn %p construct ahandle %p due brokenlink, persist: 1", CONN_GET_INST_LABEL(conn), conn, - transMsg.info.ahandle); - } - } else { - pCtx = pReq->ctx; - transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; - tDebug("%s conn %p get ahandle %p, persist: 1", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); - } - } - // buf's mem alread translated to transMsg.pCont - if (!CONN_NO_PERSIST_BY_APP(conn)) { - transMsg.info.handle = (void*)conn->refId; - transMsg.info.refId = (int64_t)(void*)conn->refId; - tDebug("%s conn %p ref by app", CONN_GET_INST_LABEL(conn), conn); - } +// pCtx = pReq ? pReq->ctx : NULL; +// transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; +// tDebug("%s conn %p get ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); +// } else { +// uint64_t ahandle = (uint64_t)pHead->ahandle; +// CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); +// if (pReq == NULL) { +// transMsg.info.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType); +// tDebug("%s conn %p construct ahandle %p by %s, persist: 1", CONN_GET_INST_LABEL(conn), conn, +// transMsg.info.ahandle, TMSG_INFO(transMsg.msgType)); +// if (!CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) { +// transMsg.code = TSDB_CODE_RPC_BROKEN_LINK; +// transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType)); +// tDebug("%s conn %p construct ahandle %p due brokenlink, persist: 1", CONN_GET_INST_LABEL(conn), conn, +// transMsg.info.ahandle); +// } +// } else { +// pCtx = pReq->ctx; +// transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; +// tDebug("%s conn %p get ahandle %p, persist: 1", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); +// } +// } +// // buf's mem alread translated to transMsg.pCont +// if (!CONN_NO_PERSIST_BY_APP(conn)) { +// transMsg.info.handle = (void*)conn->refId; +// transMsg.info.refId = (int64_t)(void*)conn->refId; +// tDebug("%s conn %p ref by app", CONN_GET_INST_LABEL(conn), conn); +// } - STraceId* trace = &transMsg.info.traceId; - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, code str:%s", CONN_GET_INST_LABEL(conn), conn, - TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, tstrerror(transMsg.code)); +// STraceId* trace = &transMsg.info.traceId; +// tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, code str:%s", CONN_GET_INST_LABEL(conn), conn, +// TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, tstrerror(transMsg.code)); - if (pCtx == NULL && CONN_NO_PERSIST_BY_APP(conn)) { - tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn); - transFreeMsg(transMsg.pCont); - return; - } - if (CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) { - tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn); - transFreeMsg(transMsg.pCont); - return; - } +// if (pCtx == NULL && CONN_NO_PERSIST_BY_APP(conn)) { +// tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn); +// transFreeMsg(transMsg.pCont); +// return; +// } +// if (CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) { +// tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn); +// transFreeMsg(transMsg.pCont); +// return; +// } - if (pReq == NULL || (pReq && pReq->type != Release)) { - if (cliNotifyCb(conn, pReq, &transMsg) != 0) { - return; - } - } - int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); - tDebug("conn %p msg refId: %" PRId64 "", conn, refId); - destroyReq(pReq); +// if (pReq == NULL || (pReq && pReq->type != Release)) { +// if (cliNotifyCb(conn, pReq, &transMsg) != 0) { +// return; +// } +// } +// int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); +// tDebug("conn %p msg refId: %" PRId64 "", conn, refId); +// destroyReq(pReq); - if (cliConnSendSeqMsg(refId, conn)) { - return; - } +// if (cliConnSendSeqMsg(refId, conn)) { +// return; +// } - if (cliMaySendCachedMsg(conn) == true) { - return; - } +// if (cliMaySendCachedMsg(conn) == true) { +// return; +// } - if (CONN_NO_PERSIST_BY_APP(conn)) { - return addConnToPool(pThrd->pool, conn); - } +// if (CONN_NO_PERSIST_BY_APP(conn)) { +// return addConnToPool(pThrd->pool, conn); +// } - (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); -} -static void cliDestroyMsgInExhandle(int64_t refId) { - if (refId == 0) return; - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh) { - taosWLockLatch(&exh->latch); - while (!QUEUE_IS_EMPTY(&exh->q)) { - queue* h = QUEUE_HEAD(&exh->q); - QUEUE_REMOVE(h); - SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); - destroyReq(t); - } - taosWUnLockLatch(&exh->latch); - (void)transReleaseExHandle(transGetRefMgt(), refId); - } -} +// (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); +// } void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { - if (transQueueEmpty(&pConn->reqs)) { - if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { - tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); - if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); - transUnrefCliHandle(pConn); - return; - } - } - SCliThrd* pThrd = pConn->hostThrd; - STrans* pInst = pThrd->pInst; - bool once = false; - do { - SCliReq* pReq = transQueuePop(&pConn->reqs); + // if (transQueueEmpty(&pConn->reqs)) { + // if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { + // tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); + // if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); + // transUnrefCliHandle(pConn); + // return; + // } + // } + // SCliThrd* pThrd = pConn->hostThrd; + // STrans* pInst = pThrd->pInst; + // bool once = false; + // do { + // SCliReq* pReq = transQueuePop(&pConn->reqs); - if (pReq == NULL && once) { - break; - } + // if (pReq == NULL && once) { + // break; + // } - if (pReq != NULL && REQUEST_NO_RESP(&pReq->msg)) { - destroyReq(pReq); - break; - } + // if (pReq != NULL && REQUEST_NO_RESP(&pReq->msg)) { + // destroyReq(pReq); + // break; + // } - SReqCtx* pCtx = pReq ? pReq->ctx : NULL; + // SReqCtx* pCtx = pReq ? pReq->ctx : NULL; - STransMsg transMsg = {0}; - transMsg.code = code == -1 ? (pConn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; - transMsg.msgType = pReq ? pReq->msg.msgType + 1 : 0; - transMsg.info.ahandle = NULL; - transMsg.info.cliVer = pInst->compatibilityVer; + // STransMsg transMsg = {0}; + // transMsg.code = code == -1 ? (pConn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; + // transMsg.msgType = pReq ? pReq->msg.msgType + 1 : 0; + // transMsg.info.ahandle = NULL; + // transMsg.info.cliVer = pInst->compatibilityVer; - if (pReq == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { - transMsg.info.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType); - tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle, - TMSG_INFO(transMsg.msgType)); - if (transMsg.info.ahandle == NULL) { - int32_t msgType = 0; - transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, &msgType); - transMsg.msgType = msgType; - tDebug("%s conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, - transMsg.info.ahandle); - } - } else { - transMsg.info.ahandle = (pReq != NULL && pReq->type != Release && pCtx) ? pCtx->ahandle : NULL; - } + // if (pReq == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { + // transMsg.info.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType); + // tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle, + // TMSG_INFO(transMsg.msgType)); + // if (transMsg.info.ahandle == NULL) { + // int32_t msgType = 0; + // transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, &msgType); + // transMsg.msgType = msgType; + // tDebug("%s conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, + // transMsg.info.ahandle); + // } + // } else { + // transMsg.info.ahandle = (pReq != NULL && pReq->type != Release && pCtx) ? pCtx->ahandle : NULL; + // } - if (pCtx == NULL || pCtx->pSem == NULL) { - if (transMsg.info.ahandle == NULL) { - if (pReq == NULL || REQUEST_NO_RESP(&pReq->msg) || pReq->type == Release) { - destroyReq(pReq); - once = true; - continue; - } - } - } + // if (pCtx == NULL || pCtx->pSem == NULL) { + // if (transMsg.info.ahandle == NULL) { + // if (pReq == NULL || REQUEST_NO_RESP(&pReq->msg) || pReq->type == Release) { + // destroyReq(pReq); + // once = true; + // continue; + // } + // } + // } - if (pReq == NULL || (pReq && pReq->type != Release)) { - int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); - cliDestroyMsgInExhandle(refId); - if (cliNotifyCb(pConn, pReq, &transMsg) != 0) { - return; - } - } - destroyReq(pReq); - tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); - } while (!transQueueEmpty(&pConn->reqs)); - if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); - transUnrefCliHandle(pConn); + // if (pReq == NULL || (pReq && pReq->type != Release)) { + // int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); + // cliDestroyMsgInExhandle(refId); + // if (cliNotifyCb(pConn, pReq, &transMsg) != 0) { + // return; + // } + // } + // destroyReq(pReq); + // tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); + // } while (!transQueueEmpty(&pConn->reqs)); + // if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); + // transUnrefCliHandle(pConn); } void cliHandleExcept(SCliConn* conn, int32_t code) { tTrace("%s conn %p except ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); @@ -946,6 +918,7 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p tDebug("conn %p get from pool, pool size:%d, dst:%s", conn, conn->list->size, conn->dstAddr); + *ppConn = conn; return 0; } @@ -989,79 +962,79 @@ static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliReq** pReq) { plist->list = nList; } - STraceId* trace = &(*pReq)->msg.info.traceId; - // no avaliable conn in pool - if (QUEUE_IS_EMPTY(&plist->conns)) { - SMsgList* list = plist->list; - if ((list)->numOfConn >= pInst->connLimitNum) { - STraceId* trace = &(*pReq)->msg.info.traceId; - if (pInst->notWaitAvaliableConn || (pInst->noDelayFp != NULL && pInst->noDelayFp((*pReq)->msg.msgType))) { - tDebug("%s msg %s not to send, reason: %s", pInst->label, TMSG_INFO((*pReq)->msg.msgType), - tstrerror(TSDB_CODE_RPC_NETWORK_BUSY)); - doNotifyCb(*pReq, pThrd, TSDB_CODE_RPC_NETWORK_BUSY); - *pReq = NULL; - return NULL; - } + // STraceId* trace = &(*pReq)->msg.info.traceId; + // // no avaliable conn in pool + // if (QUEUE_IS_EMPTY(&plist->conns)) { + // SMsgList* list = plist->list; + // if ((list)->numOfConn >= pInst->connLimitNum) { + // STraceId* trace = &(*pReq)->msg.info.traceId; + // if (pInst->notWaitAvaliableConn || (pInst->noDelayFp != NULL && pInst->noDelayFp((*pReq)->msg.msgType))) { + // tDebug("%s msg %s not to send, reason: %s", pInst->label, TMSG_INFO((*pReq)->msg.msgType), + // tstrerror(TSDB_CODE_RPC_NETWORK_BUSY)); + // doNotifyCb(*pReq, pThrd, TSDB_CODE_RPC_NETWORK_BUSY); + // *pReq = NULL; + // return NULL; + // } - STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); - if (arg == NULL) { - doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pReq = NULL; - return NULL; - } - arg->param1 = *pReq; - arg->param2 = pThrd; + // STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + // if (arg == NULL) { + // doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + // *pReq = NULL; + // return NULL; + // } + // arg->param1 = *pReq; + // arg->param2 = pThrd; - SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); - if (task == NULL) { - taosMemoryFree(arg); - doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pReq = NULL; - return NULL; - } - (*pReq)->ctx->task = task; - tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); - QUEUE_PUSH(&(list)->msgQ, &(*pReq)->q); - *pReq = NULL; - } else { - // send msg in delay queue - if (!(QUEUE_IS_EMPTY(&(list)->msgQ))) { - STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); - if (arg == NULL) { - doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pReq = NULL; - return NULL; - } - arg->param1 = *pReq; - arg->param2 = pThrd; + // SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); + // if (task == NULL) { + // taosMemoryFree(arg); + // doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + // *pReq = NULL; + // return NULL; + // } + // (*pReq)->ctx->task = task; + // tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); + // QUEUE_PUSH(&(list)->msgQ, &(*pReq)->q); + // *pReq = NULL; + // } else { + // // send msg in delay queue + // if (!(QUEUE_IS_EMPTY(&(list)->msgQ))) { + // STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + // if (arg == NULL) { + // doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + // *pReq = NULL; + // return NULL; + // } + // arg->param1 = *pReq; + // arg->param2 = pThrd; - SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); - if (task == NULL) { - taosMemoryFree(arg); - doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pReq = NULL; - return NULL; - } + // SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); + // if (task == NULL) { + // taosMemoryFree(arg); + // doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); + // *pReq = NULL; + // return NULL; + // } - (*pReq)->ctx->task = task; - tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); + // (*pReq)->ctx->task = task; + // tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); - QUEUE_PUSH(&(list)->msgQ, &(*pReq)->q); - queue* h = QUEUE_HEAD(&(list)->msgQ); - QUEUE_REMOVE(h); - SCliReq* ans = QUEUE_DATA(h, SCliReq, q); + // QUEUE_PUSH(&(list)->msgQ, &(*pReq)->q); + // queue* h = QUEUE_HEAD(&(list)->msgQ); + // QUEUE_REMOVE(h); + // SCliReq* ans = QUEUE_DATA(h, SCliReq, q); - *pReq = ans; + // *pReq = ans; - trace = &(*pReq)->msg.info.traceId; - tGTrace("%s msg %s pop from delay queue, start to send", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); - transDQCancel(pThrd->waitConnQueue, ans->ctx->task); - } - list->numOfConn++; - } - tDebug("%s numOfConn: %d, limit: %d, dst:%s", pInst->label, list->numOfConn, pInst->connLimitNum, key); - return NULL; - } + // trace = &(*pReq)->msg.info.traceId; + // tGTrace("%s msg %s pop from delay queue, start to send", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); + // transDQCancel(pThrd->waitConnQueue, ans->ctx->task); + // } + // list->numOfConn++; + // } + // tDebug("%s numOfConn: %d, limit: %d, dst:%s", pInst->label, list->numOfConn, pInst->connLimitNum, key); + // return NULL; + // } queue* h = QUEUE_TAIL(&plist->conns); plist->size -= 1; @@ -1081,6 +1054,8 @@ static void addConnToPool(void* pool, SCliConn* conn) { if (conn->status == ConnInPool) { return; } + + conn->seq = 0; int32_t code = allocConnRef(conn, true); if (code != 0) { cliDestroyConn(conn, true); @@ -1115,7 +1090,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { (void)transQueuePush(&conn->reqs, pReq); conn->status = ConnNormal; - (void)cliSend(conn); + (void)cliSend2(conn); return; } @@ -1219,7 +1194,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { cliHandleExcept(conn, -1); break; } else { - cliHandleResp(conn); + cliHandleResp2(conn); } } return; @@ -1373,59 +1348,59 @@ static void cliDestroy(uv_handle_t* handle) { taosMemoryFree(conn); } -static bool cliHandleNoResp(SCliConn* conn) { - bool res = false; - if (!transQueueEmpty(&conn->reqs)) { - SCliReq* pReq = transQueueGet(&conn->reqs, 0); - if (REQUEST_NO_RESP(&pReq->msg)) { - (void)transQueuePop(&conn->reqs); - destroyReq(pReq); - res = true; - } - if (res == true) { - if (cliMaySendCachedMsg(conn) == false) { - SCliThrd* thrd = conn->hostThrd; - addConnToPool(thrd->pool, conn); - res = false; - } else { - res = true; - } - } - } - return res; -} +// static bool cliHandleNoResp(SCliConn* conn) { +// bool res = false; +// if (!transQueueEmpty(&conn->reqs)) { +// SCliReq* pReq = transQueueGet(&conn->reqs, 0); +// if (REQUEST_NO_RESP(&pReq->msg)) { +// (void)transQueuePop(&conn->reqs); +// destroyReq(pReq); +// res = true; +// } +// if (res == true) { +// if (cliMaySendCachedMsg(conn) == false) { +// SCliThrd* thrd = conn->hostThrd; +// addConnToPool(thrd->pool, conn); +// res = false; +// } else { +// res = true; +// } +// } +// } +// return res; +// } static void cliSendCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); - SCliConn* pConn = transReqQueueRemove(req); - if (pConn == NULL) return; + // SCliConn* pConn = transReqQueueRemove(req); + // if (pConn == NULL) return; - SCliReq* pReq = transQueueGet(&pConn->reqs, 0); - if (pReq != NULL) { - int64_t cost = taosGetTimestampUs() - pReq->st; - if (cost > 1000 * 50) { - tTrace("%s conn %p send cost:%dus ", CONN_GET_INST_LABEL(pConn), pConn, (int)cost); - } - } - if (pReq != NULL && pReq->msg.contLen == 0 && pReq->msg.pCont != 0) { - rpcFreeCont(pReq->msg.pCont); - pReq->msg.pCont = 0; - } + // SCliReq* pReq = transQueueGet(&pConn->reqs, 0); + // if (pReq != NULL) { + // int64_t cost = taosGetTimestampUs() - pReq->st; + // if (cost > 1000 * 50) { + // tTrace("%s conn %p send cost:%dus ", CONN_GET_INST_LABEL(pConn), pConn, (int)cost); + // } + // } + // if (pReq != NULL && pReq->msg.contLen == 0 && pReq->msg.pCont != 0) { + // rpcFreeCont(pReq->msg.pCont); + // pReq->msg.pCont = 0; + // } - if (status == 0) { - tDebug("%s conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); - } else { - if (!uv_is_closing((uv_handle_t*)&pConn->stream)) { - tError("%s conn %p failed to write:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); - cliHandleExcept(pConn, -1); - } - return; - } - if (cliHandleNoResp(pConn) == true) { - tTrace("%s conn %p no resp required", CONN_GET_INST_LABEL(pConn), pConn); - return; - } - (void)uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); + // if (status == 0) { + // tDebug("%s conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); + // } else { + // if (!uv_is_closing((uv_handle_t*)&pConn->stream)) { + // tError("%s conn %p failed to write:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); + // cliHandleExcept(pConn, -1); + // } + // return; + // } + // if (cliHandleNoResp(pConn) == true) { + // tTrace("%s conn %p no resp required", CONN_GET_INST_LABEL(pConn), pConn); + // return; + // } + // (void)uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); } static void cliHandleBatch_shareConnExcept(SCliConn* conn) { @@ -1459,9 +1434,34 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { if (T_REF_VAL_GET(conn) > 1) transUnrefCliHandle(conn); transUnrefCliHandle(conn); } + +static void cliConnRmReqs(SCliConn* conn) { + for (int i = 0; i < transQueueSize(&conn->reqs); i++) { + SCliReq* pReq = transQueueGet(&conn->reqs, i); + if (pReq->sent == 1 && REQUEST_NO_RESP(&pReq->msg)) { + transQueueRm(&conn->reqs, i); + destroyReq(pReq); + } + } +} + +static int32_t cliShouldSendMsg(SCliConn* conn) { + for (int i = 0; i < transQueueSize(&conn->reqs); i++) { + SCliReq* pReq = transQueueGet(&conn->reqs, i); + if (pReq->sent == 0) { + // pReq->sent = 1; + // pReq->seq = conn->seq; + return 1; + } + } + return 0; +} static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { SCliConn* conn = req->data; + SCliThrd* pThrd = conn->hostThrd; conn->shareCnt -= 1; + + cliConnRmReqs(conn); if (status != 0) { tDebug("%s conn %p failed to send batch msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); if (!uv_is_closing((uv_handle_t*)&conn->stream)) { @@ -1469,7 +1469,16 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { } return; } - uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + int ret = uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + + if (ret != 0) { + tError("%s conn %p failed to start read, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(ret)); + cliHandleBatch_shareConnExcept(conn); + } + + if (cliShouldSendMsg(conn) == 1) { + cliSendBatch_shareConn(conn); + } taosMemoryFree(req); } void cliSendBatch_shareConn(SCliConn* pConn) { @@ -1518,7 +1527,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pHead->compatibilityVer = htonl(pInst->compatibilityVer); } pHead->timestamp = taosHton64(taosGetTimestampUs()); - pHead->seqNum = pConn->seq; + pHead->seqNum = htonl(pConn->seq); if (pHead->comp == 0) { if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { @@ -1532,7 +1541,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { totalLen += msgLen; pCliMsg->sent = 1; - pCliMsg->seq = pHead->seqNum; + pCliMsg->seq = pConn->seq; } uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); @@ -1577,7 +1586,7 @@ void cliSendBatch(SCliConn* pConn) { } pReq->contLen = 0; } - + pConn->seq++; int msgLen = transMsgLenFromCont(pReq->contLen); STransMsgHead* pHead = transHeadFromCont(pReq->pCont); @@ -1595,6 +1604,7 @@ void cliSendBatch(SCliConn* pConn) { pHead->compatibilityVer = htonl(pInst->compatibilityVer); } pHead->timestamp = taosHton64(taosGetTimestampUs()); + pHead->seqNum = htonl(pConn->seq); if (pHead->comp == 0 && pReq->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { @@ -1637,10 +1647,14 @@ _exception: int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; transQueuePush(&pConn->reqs, pCliMsg); - code = cliSend(pConn); + code = cliSend2(pConn); return code; } +int32_t cliSend2(SCliConn* pConn) { + cliSendBatch_shareConn(pConn); + return 0; +} int32_t cliSend(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; @@ -1677,7 +1691,7 @@ int32_t cliSend(SCliConn* pConn) { pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->version = TRANS_VER; pHead->compatibilityVer = htonl(pInst->compatibilityVer); - pHead->seqNum = pConn->seq++; + pHead->seqNum = htonl(pConn->seq++); } pHead->timestamp = taosHton64(taosGetTimestampUs()); @@ -1957,7 +1971,7 @@ void cliConnCb(uv_connect_t* req, int status) { return cliSendBatch_shareConn(pConn); } - (void)cliSend(pConn); + (void)cliSend2(pConn); } static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code) { @@ -2019,7 +2033,7 @@ static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { if (!transQueuePush(&conn->reqs, pReq)) { return; } - (void)cliSend(conn); + (void)cliSend2(conn); } else { tError("%s conn %p already released", CONN_GET_INST_LABEL(conn), conn); destroyReq(pReq); @@ -2298,15 +2312,15 @@ _exception: } void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq) { - STrans* pInst = pThrd->pInst; - if (pInst->shareConn == 1) { - return cliHandleReq__shareConn(pThrd, pReq); - } else { - return cliHandleReq__noShareConn(pThrd, pReq); - } + // STrans* pInst = pThrd->pInst; + // if (pInst->shareConn == 1) { + // return cliHandleReq__shareConn(pThrd, pReq); + // } else { + return cliHandleReq__noShareConn(pThrd, pReq); + //} } -static void cliDealReq(queue* wq, SCliThrd* pThrd) { +static void cliDoReq(queue* wq, SCliThrd* pThrd) { int count = 0; while (!QUEUE_IS_EMPTY(wq)) { @@ -2464,7 +2478,7 @@ static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliReq* p *ppBatch = pBatch; return 0; } -static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) { +static void cliDoBatchReq(queue* wq, SCliThrd* pThrd) { STrans* pInst = pThrd->pInst; int32_t code = 0; @@ -2674,9 +2688,8 @@ _err: terrno = code; return NULL; } - int32_t initCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { - SCliThrd* pThrd = pThrd; + SCliThrd* pThrd = thrd; return cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); } int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { @@ -3264,12 +3277,6 @@ int32_t cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - // if (pReq == NULL || pReq->ctx == NULL) { - // tTrace("%s conn %p handle resp", pInst->label, pConn); - // pInst->cfp(pInst->parent, pResp, NULL); - // return 0; - // } - if (cliMayRetry(pConn, pReq, pResp)) { return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 8acbe9f273..6b5c15eae3 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -65,9 +65,9 @@ typedef struct SSvrMsg { STransMsg msg; queue q; STransMsgType type; - - void* arg; - FilteFunc func; + int32_t seqNum; + void* arg; + FilteFunc func; } SSvrMsg; @@ -471,7 +471,7 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; - if (pHead->seqNum != 0) { + if (pHead->seqNum == 0) { ASSERT(0); } // pHead->noResp = 1, @@ -487,6 +487,7 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.info.cliVer = htonl(pHead->compatibilityVer); transMsg.info.forbiddenIp = forbiddenIp; transMsg.info.noResp = pHead->noResp == 1 ? 1 : 0; + transMsg.info.seqNum = htonl(pHead->seqNum); uvMaySetConnAcquired(pConn, pHead); @@ -652,6 +653,7 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->compatibilityVer = htonl(((STrans*)pConn->pInst)->compatibilityVer); pHead->version = TRANS_VER; + pHead->seqNum = htonl(pMsg->info.seqNum); // handle invalid drop_task resp, TD-20098 if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { @@ -793,6 +795,8 @@ void uvWorkerAsyncCb(uv_async_t* handle) { SExHandle* exh1 = transMsg.info.handle; int64_t refId = transMsg.info.refId; + msg->seqNum = transMsg.info.seqNum; + SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), refId); if (exh2 == NULL || exh1 != exh2) { tTrace("handle except msg %p, ignore it", exh1); From f9290cf13f46ac8a0b97650116259d682e554256 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 4 Sep 2024 16:50:52 +0800 Subject: [PATCH 047/240] refactor transport --- source/dnode/mnode/impl/src/mndQuery.c | 31 +- source/libs/scheduler/src/schRemote.c | 1 + source/libs/transport/src/transCli.c | 531 ++++++------------------- source/libs/transport/src/transSvr.c | 52 +-- 4 files changed, 154 insertions(+), 461 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index c743aafd13..899439a31a 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -30,9 +30,9 @@ void mndPostProcessQueryMsg(SRpcMsg *pMsg) { (void)qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg); } -int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo* pInfo) { - int32_t code = -1; - SMnode *pMnode = pMsg->info.node; +int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo *pInfo) { + int32_t code = -1; + SMnode *pMnode = pMsg->info.node; SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb, .pWorkerCb = pInfo->workerCb}; @@ -67,26 +67,25 @@ int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo* pInfo) { return code; } - -static FORCE_INLINE void mnodeFreeSBatchRspMsg(void* p) { +static FORCE_INLINE void mnodeFreeSBatchRspMsg(void *p) { if (NULL == p) { return; } - SBatchRspMsg* pRsp = (SBatchRspMsg*)p; + SBatchRspMsg *pRsp = (SBatchRspMsg *)p; rpcFreeCont(pRsp->msg); } int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { - int32_t code = 0; - int32_t rspSize = 0; - SBatchReq batchReq = {0}; - SBatchMsg req = {0}; + int32_t code = 0; + int32_t rspSize = 0; + SBatchReq batchReq = {0}; + SBatchMsg req = {0}; SBatchRspMsg rsp = {0}; - SBatchRsp batchRsp = {0}; - SRpcMsg reqMsg = *pMsg; - void *pRsp = NULL; - SMnode *pMnode = pMsg->info.node; + SBatchRsp batchRsp = {0}; + SRpcMsg reqMsg = *pMsg; + void *pRsp = NULL; + SMnode *pMnode = pMsg->info.node; if ((code = tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) != 0) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -94,7 +93,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { goto _exit; } - int32_t msgNum = taosArrayGetSize(batchReq.pMsgs); + int32_t msgNum = taosArrayGetSize(batchReq.pMsgs); if (msgNum >= MAX_META_MSG_IN_BATCH) { code = TSDB_CODE_INVALID_MSG; mError("too many msgs %d in mnode batch meta req", msgNum); @@ -108,7 +107,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { } for (int32_t i = 0; i < msgNum; ++i) { - SBatchMsg* req = taosArrayGet(batchReq.pMsgs, i); + SBatchMsg *req = taosArrayGet(batchReq.pMsgs, i); reqMsg.msgType = req->msgType; reqMsg.pCont = req->msg; diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 9215254f9c..14118f189b 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -982,6 +982,7 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, SSchTrans *trans, SQuery SCH_ERR_JRET(code); } trans->pHandle = (void *)refId; + pMsgSendInfo->msgInfo.handle = trans->pHandle; } if (pJob && pTask) { diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a3cd6eacd0..4a7cf8da42 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -80,6 +80,7 @@ typedef struct SCliConn { HeapNode node; // for heap int8_t inHeap; + int32_t reqRefCnt; uint32_t clientIp; uint32_t serverIp; @@ -172,6 +173,7 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn); static void cliSendBatch_shareConnCb(uv_write_t* req, int status); void cliSendBatch_shareConn(SCliConn* pConn); int32_t cliSend2(SCliConn* conn); +bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead); // register conn timer static void cliConnTimeout(uv_timer_t* handle); // register timer for read @@ -190,7 +192,7 @@ static void cliAsyncCb(uv_async_t* handle); // static void cliIdleCb(uv_idle_t* handle); // static void cliPrepareCb(uv_prepare_t* handle); -static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd); +// static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd); static void cliSendBatchCb(uv_write_t* req, int status); SCliBatch* cliGetHeadFromList(SCliBatchList* pList); @@ -202,11 +204,11 @@ static int32_t allocConnRef(SCliConn* conn, bool update); static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); void cliResetConnTimer(SCliConn* conn); -static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); -static void cliDestroy(uv_handle_t* handle); -static int32_t cliSend(SCliConn* pConn); -static void cliSendBatch(SCliConn* pConn); -static void cliDestroyConnMsgs(SCliConn* conn, bool destroy); +static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); +static void cliDestroy(uv_handle_t* handle); +// static int32_t 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, SCliReq** pReq); @@ -459,16 +461,6 @@ void cliResetConnTimer(SCliConn* conn) { void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } -bool cliShouldAddConnToPool(SCliConn* conn) { - SCliThrd* pThrd = conn->hostThrd; - bool empty = transQueueEmpty(&conn->reqs); - if (empty) { - (void)delConnFromHeapCache(pThrd->connHeapCache, conn); - } - - return empty; -} - int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { int32_t code = 0; for (int i = 0; i < transQueueSize(&conn->reqs); i++) { @@ -485,6 +477,7 @@ int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { int8_t cliMayRecycleConn(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; if (transQueueSize(&conn->reqs) == 0) { + (void)delConnFromHeapCache(pThrd->connHeapCache, conn); addConnToPool(pThrd->pool, conn); return 1; } @@ -494,12 +487,13 @@ int8_t cliMayRecycleConn(SCliConn* conn) { int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHead) { pResp->contLen = transContLenFromMsg(pHead->msgLen); pResp->pCont = transContFromHead((char*)pHead); - pResp->code = pReq->msg.code; - pResp->msgType = pReq->msg.msgType; + pResp->code = pHead->code; + pResp->msgType = pHead->msgType; pResp->info.ahandle = pReq->ctx ? pReq->ctx->ahandle : NULL; - pResp->info.traceId = pReq->msg.info.traceId; - pResp->info.hasEpSet = pReq->msg.info.hasEpSet; - pResp->info.cliVer = pReq->msg.info.cliVer; + pResp->info.traceId = pHead->traceId; + pResp->info.hasEpSet = pHead->hasEpSet; + pResp->info.cliVer = htonl(pHead->compatibilityVer); + pResp->info.seqNum = htonl(pHead->seqNum); return 0; } void cliHandleResp2(SCliConn* conn) { @@ -525,17 +519,27 @@ void cliHandleResp2(SCliConn* conn) { return; } + pHead->code = htonl(pHead->code); + pHead->msgLen = htonl(pHead->msgLen); + SCliReq* pReq = NULL; int32_t seq = htonl(pHead->seqNum); code = cliGetReqBySeq(conn, seq, &pReq); if (code != 0) { - tDebug("%s conn %p recv unexpected packet, reason:%s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + if (cliConnRmReleaseReq(conn, pHead)) { + return; + } else { + } + tDebug("%s conn %p recv unexpected packet, seqNum:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, + tstrerror(code)); // TODO: notify cb + + if (cliMayRecycleConn(conn)) { + return; + } return; } - pHead->code = htonl(pHead->code); - pHead->msgLen = htonl(pHead->msgLen); // TODO handle release req // if (cliRecvReleaseReq(conn, pHead)) { // return; @@ -545,6 +549,9 @@ void cliHandleResp2(SCliConn* conn) { code = cliBuildRespFromCont(pReq, &resp, pHead); if (code != 0) { tDebug("%s conn %p recv invalid packet, seq %d not found", CONN_GET_INST_LABEL(conn), conn, seq); + } else { + tDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%d", CONN_GET_INST_LABEL(conn), conn, + TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq); } code = cliNotifyCb(conn, pReq, &resp); @@ -1054,6 +1061,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { if (conn->status == ConnInPool) { return; } + uv_read_stop(conn->stream); conn->seq = 0; int32_t code = allocConnRef(conn, true); @@ -1240,7 +1248,7 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); - TAOS_CHECK_GOTO(addConnToHeapCache(pThrd->connHeapCache, pConn), NULL, _exception); + // TAOS_CHECK_GOTO(addConnToHeapCache(pThrd->connHeapCache, pConn), NULL, _exception); transQueuePush(&pConn->reqs, pReq); @@ -1348,60 +1356,6 @@ static void cliDestroy(uv_handle_t* handle) { taosMemoryFree(conn); } -// static bool cliHandleNoResp(SCliConn* conn) { -// bool res = false; -// if (!transQueueEmpty(&conn->reqs)) { -// SCliReq* pReq = transQueueGet(&conn->reqs, 0); -// if (REQUEST_NO_RESP(&pReq->msg)) { -// (void)transQueuePop(&conn->reqs); -// destroyReq(pReq); -// res = true; -// } -// if (res == true) { -// if (cliMaySendCachedMsg(conn) == false) { -// SCliThrd* thrd = conn->hostThrd; -// addConnToPool(thrd->pool, conn); -// res = false; -// } else { -// res = true; -// } -// } -// } -// return res; -// } -static void cliSendCb(uv_write_t* req, int status) { - STUB_RAND_NETWORK_ERR(status); - - // SCliConn* pConn = transReqQueueRemove(req); - // if (pConn == NULL) return; - - // SCliReq* pReq = transQueueGet(&pConn->reqs, 0); - // if (pReq != NULL) { - // int64_t cost = taosGetTimestampUs() - pReq->st; - // if (cost > 1000 * 50) { - // tTrace("%s conn %p send cost:%dus ", CONN_GET_INST_LABEL(pConn), pConn, (int)cost); - // } - // } - // if (pReq != NULL && pReq->msg.contLen == 0 && pReq->msg.pCont != 0) { - // rpcFreeCont(pReq->msg.pCont); - // pReq->msg.pCont = 0; - // } - - // if (status == 0) { - // tDebug("%s conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); - // } else { - // if (!uv_is_closing((uv_handle_t*)&pConn->stream)) { - // tError("%s conn %p failed to write:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); - // cliHandleExcept(pConn, -1); - // } - // return; - // } - // if (cliHandleNoResp(pConn) == true) { - // tTrace("%s conn %p no resp required", CONN_GET_INST_LABEL(pConn), pConn); - // return; - // } - // (void)uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); -} static void cliHandleBatch_shareConnExcept(SCliConn* conn) { int32_t code = 0; @@ -1449,8 +1403,6 @@ static int32_t cliShouldSendMsg(SCliConn* conn) { for (int i = 0; i < transQueueSize(&conn->reqs); i++) { SCliReq* pReq = transQueueGet(&conn->reqs, i); if (pReq->sent == 0) { - // pReq->sent = 1; - // pReq->seq = conn->seq; return 1; } } @@ -1463,23 +1415,18 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { cliConnRmReqs(conn); if (status != 0) { - tDebug("%s conn %p failed to send batch msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); + tDebug("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); if (!uv_is_closing((uv_handle_t*)&conn->stream)) { cliHandleBatch_shareConnExcept(conn); } return; } - int ret = uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + taosMemoryFree(req); - if (ret != 0) { - tError("%s conn %p failed to start read, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(ret)); - cliHandleBatch_shareConnExcept(conn); - } - - if (cliShouldSendMsg(conn) == 1) { + if (!cliMayRecycleConn(conn)) { cliSendBatch_shareConn(conn); } - taosMemoryFree(req); } void cliSendBatch_shareConn(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; @@ -1489,7 +1436,6 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int32_t totalLen = 0; if (size == 0) { tError("%s conn %p not msg to send", pInst->label, pConn); - ASSERT(0); return; } uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); @@ -1542,108 +1488,24 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pCliMsg->sent = 1; pCliMsg->seq = pConn->seq; + + STraceId* trace = &pCliMsg->msg.info.traceId; + tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d", CONN_GET_INST_LABEL(pConn), pConn, + TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq); + } + if (j == 0) { + taosMemoryFree(wb); + return; } uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); req->data = pConn; pConn->shareCnt += 1; - tDebug("%s conn %p start to send batch msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, - totalLen); + tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliSendBatch_shareConnCb); taosMemoryFree(wb); } -void cliSendBatch(SCliConn* pConn) { - int32_t code = 0; - SCliThrd* pThrd = pConn->hostThrd; - STrans* pInst = pThrd->pInst; - SCliBatch* pBatch = pConn->pBatch; - int32_t wLen = pBatch->wLen; - - pBatch->pList->connCnt += 1; - - uv_buf_t* wb = taosMemoryCalloc(wLen, sizeof(uv_buf_t)); - if (wb == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); - goto _exception; - } - - int i = 0; - queue* h = NULL; - QUEUE_FOREACH(h, &pBatch->wq) { - SCliReq* pCliMsg = QUEUE_DATA(h, SCliReq, q); - - SReqCtx* pCtx = pCliMsg->ctx; - - STransMsg* pReq = (STransMsg*)(&pCliMsg->msg); - if (pReq->pCont == 0) { - pReq->pCont = (void*)rpcMallocCont(0); - if (pReq->pCont == NULL) { - code = TSDB_CODE_OUT_OF_BUFFER; - tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); - goto _exception; - } - pReq->contLen = 0; - } - pConn->seq++; - int msgLen = transMsgLenFromCont(pReq->contLen); - STransMsgHead* pHead = transHeadFromCont(pReq->pCont); - - if (pHead->comp == 0) { - pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; - pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; - pHead->persist = REQUEST_PERSIS_HANDLE(pReq) ? 1 : 0; - pHead->msgType = pReq->msgType; - pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; - memcpy(pHead->user, pInst->user, strlen(pInst->user)); - pHead->traceId = pReq->info.traceId; - pHead->magicNum = htonl(TRANS_MAGIC_NUM); - pHead->version = TRANS_VER; - pHead->compatibilityVer = htonl(pInst->compatibilityVer); - } - pHead->timestamp = taosHton64(taosGetTimestampUs()); - pHead->seqNum = htonl(pConn->seq); - - if (pHead->comp == 0 && pReq->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { - if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { - msgLen = transCompressMsg(pReq->pCont, pReq->contLen) + sizeof(STransMsgHead); - pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - } - } else { - msgLen = (int32_t)ntohl((uint32_t)(pHead->msgLen)); - } - wb[i++] = uv_buf_init((char*)pHead, msgLen); - } - - uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); - if (req == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); - goto _exception; - } - 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); - - code = uv_write(req, (uv_stream_t*)pConn->stream, wb, wLen, cliSendBatchCb); - if (code != 0) { - tDebug("%s conn %p failed to to send batch msg since %s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(code)); - goto _exception; - } - - taosMemoryFree(wb); - return; - -_exception: - cliDestroyBatch(pBatch); - taosMemoryFree(wb); - pConn->pBatch = NULL; - return; -} - -// int32_t cliSend2(SCliConn* pConn) {} int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; transQueuePush(&pConn->reqs, pCliMsg); @@ -1655,79 +1517,6 @@ int32_t cliSend2(SCliConn* pConn) { cliSendBatch_shareConn(pConn); return 0; } -int32_t cliSend(SCliConn* pConn) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pInst = pThrd->pInst; - SCliReq* pCliReq = NULL; - int32_t code = cliConnFindToSendMsg(pConn, &pCliReq); - if (code != 0) { - return code; - } - - SReqCtx* pCtx = pCliReq->ctx; - - STransMsg* pReq = (STransMsg*)(&pCliReq->msg); - if (pReq->pCont == 0) { - pReq->pCont = (void*)rpcMallocCont(0); - if (pReq->pCont == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tDebug("malloc memory: %p", pReq->pCont); - pReq->contLen = 0; - } - - int msgLen = transMsgLenFromCont(pReq->contLen); - STransMsgHead* pHead = transHeadFromCont(pReq->pCont); - - if (pHead->comp == 0) { - pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; - pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; - pHead->persist = REQUEST_PERSIS_HANDLE(pReq) ? 1 : 0; - pHead->msgType = pReq->msgType; - pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - pHead->release = REQUEST_RELEASE_HANDLE(pCliReq) ? 1 : 0; - memcpy(pHead->user, pInst->user, strlen(pInst->user)); - pHead->traceId = pReq->info.traceId; - pHead->magicNum = htonl(TRANS_MAGIC_NUM); - pHead->version = TRANS_VER; - pHead->compatibilityVer = htonl(pInst->compatibilityVer); - pHead->seqNum = htonl(pConn->seq++); - } - - pHead->timestamp = taosHton64(taosGetTimestampUs()); - - STraceId* trace = &pReq->info.traceId; - - if (pHead->comp == 0 && pReq->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { - if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { - msgLen = transCompressMsg(pReq->pCont, pReq->contLen) + sizeof(STransMsgHead); - pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - } - } else { - msgLen = (int32_t)ntohl((uint32_t)(pHead->msgLen)); - } - - tGDebug("%s conn %p %s is sent to %s, local info %s, len:%d", CONN_GET_INST_LABEL(pConn), pConn, - TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, msgLen); - - uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); - uv_write_t* aReq = transReqQueuePush(&pConn->wreqQueue); - if (aReq == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); - } - - pCliReq->sent = 1; - int status = uv_write(aReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); - if (status != 0) { - tGError("%s conn %p failed to send msg:%s, errmsg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), - uv_err_name(status)); - TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _exception); - } - - return TSDB_CODE_RPC_ASYNC_IN_PROCESS; -_exception: - return code; -} static void cliDestroyBatch(SCliBatch* pBatch) { if (pBatch == NULL) return; @@ -1808,83 +1597,6 @@ _exception2: // // taosMemoryFree(conn); return code; } -static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { - if (pBatch == NULL || pBatch->wLen == 0 || QUEUE_IS_EMPTY(&pBatch->wq)) { - return; - } - - int32_t code = 0; - if (pThrd->quit == true) { - cliDestroyBatch(pBatch); - return; - } - - STrans* pInst = pThrd->pInst; - SCliBatchList* pList = pBatch->pList; - - bool exceed = false; - SCliConn* conn = getConnFromPool(pThrd, pList->dst, &exceed); - - if (conn == NULL && exceed) { - tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d", pInst->label, pBatch->wLen, - pBatch->batchSize, pInst->connLimitNum); - cliDestroyBatch(pBatch); - return; - } - if (conn == NULL) { - code = cliCreateConn(pThrd, &conn, pList->ip, pList->port); - if (code != 0) { - tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d, reason:%s", pInst->label, - pBatch->wLen, pBatch->batchSize, pInst->connLimitNum, tstrerror(code)); - cliDestroyBatch(pBatch); - return; - } - - conn->pBatch = pBatch; - code = cliDoConn(pThrd, conn); - if (code != 0) { - } - return; - } - - conn->pBatch = pBatch; - cliSendBatch(conn); -} -static void cliSendBatchCb(uv_write_t* req, int status) { - STUB_RAND_NETWORK_ERR(status); - SCliConn* conn = req->data; - SCliThrd* thrd = conn->hostThrd; - SCliBatch* p = conn->pBatch; - conn->pBatch = NULL; - - SCliBatch* nxtBatch = cliGetHeadFromList(p->pList); - p->pList->connCnt -= 1; - - if (status != 0) { - tDebug("%s conn %p failed to send batch msg, batch size:%d, msgLen:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, - p->wLen, p->batchSize, uv_err_name(status)); - - if (!uv_is_closing((uv_handle_t*)&conn->stream)) cliHandleExcept(conn, -1); - - cliHandleBatchReq(nxtBatch, thrd); - } else { - tDebug("%s conn %p succ to send batch msg, batch size:%d, msgLen:%d", CONN_GET_INST_LABEL(conn), conn, p->wLen, - p->batchSize); - if (!uv_is_closing((uv_handle_t*)&conn->stream) && conn->broken == false) { - if (nxtBatch != NULL) { - conn->pBatch = nxtBatch; - cliSendBatch(conn); - } else { - addConnToPool(thrd->pool, conn); - } - } else { - cliDestroyBatch(nxtBatch); - } - } - - cliDestroyBatch(p); - taosMemoryFree(req); -} static void cliHandleFastFail_resp(SCliConn* pConn, int status) { SCliThrd* pThrd = pConn->hostThrd; @@ -1963,13 +1675,8 @@ void cliConnCb(uv_connect_t* req, int status) { cliConnSetSockInfo(pConn); + addConnToHeapCache(pThrd->connHeapCache, pConn); tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); - if (pConn->pBatch != NULL) { - return cliSendBatch(pConn); - } - if (pConn->inHeap) { - return cliSendBatch_shareConn(pConn); - } (void)cliSend2(pConn); } @@ -2236,71 +1943,34 @@ static void doFreeTimeoutMsg(void* param) { taosMemoryFree(arg); } -void cliHandleReq__shareConn(SCliThrd* pThrd, SCliReq* pReq) { - int32_t code = 0; - int32_t lino = 0; - STransMsg resp = {0}; - - code = (pThrd->initCb)(pThrd, pReq, NULL); - TAOS_CHECK_GOTO(code, &lino, _exception); - - STraceId* trace = &pReq->msg.info.traceId; - STrans* pInst = pThrd->pInst; - - char addr[TSDB_FQDN_LEN + 64] = {0}; - char* ip = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); - int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); - CONN_CONSTRUCT_HASH_KEY(addr, ip, port); - - SCliConn* pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); - if (pConn == NULL) { - tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); - bool ignore = false; - pConn = getConnFromPool(pThrd, addr, &ignore); - if (pConn != NULL) { - addConnToHeapCache(pThrd->connHeapCache, pConn); - transQueuePush(&pConn->reqs, pReq); - return cliSendBatch_shareConn(pConn); - } - } else { - tGTrace("%s conn %p get from heap cache", CONN_GET_INST_LABEL(pConn), pConn); - transQueuePush(&pConn->reqs, pReq); - cliSendBatch_shareConn(pConn); - return; - } - - TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); - - TAOS_CHECK_GOTO(addConnToHeapCache(pThrd->connHeapCache, pConn), NULL, _exception); - - transQueuePush(&pConn->reqs, pReq); - - code = cliDoConn(pThrd, pConn); -_exception: - - resp.code = code; - (void)(pThrd->notifyExceptCb)(pThrd, pReq, &resp); - return; -} - void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { int32_t lino = 0; STransMsg resp = {0}; int32_t code = (pThrd->initCb)(pThrd, pReq, NULL); TAOS_CHECK_GOTO(code, &lino, _exception); + char addr[TSDB_FQDN_LEN + 64] = {0}; + char* ip = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); + int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); + CONN_CONSTRUCT_HASH_KEY(addr, ip, port); + STrans* pInst = pThrd->pInst; SCliConn* pConn = NULL; - code = cliGetOrCreateConn(pThrd, pReq, &pConn); - if (code == TSDB_CODE_RPC_MAX_SESSIONS) { - TAOS_CHECK_GOTO(code, &lino, _exception); - } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { - // do nothing, notiy - return; - } else { - code = cliSendReq(pConn, pReq); + pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); + if (pConn == NULL) { + code = cliGetOrCreateConn(pThrd, pReq, &pConn); + if (code == TSDB_CODE_RPC_MAX_SESSIONS) { + TAOS_CHECK_GOTO(code, &lino, _exception); + } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + // do nothing, notiy + return; + } else { + ASSERT(code == 0); + addConnToHeapCache(pThrd->connHeapCache, pConn); + } } + code = cliSendReq(pConn, pReq); tTrace("%s conn %p ready", pInst->label, pConn); return; @@ -2311,14 +1981,7 @@ _exception: return; } -void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq) { - // STrans* pInst = pThrd->pInst; - // if (pInst->shareConn == 1) { - // return cliHandleReq__shareConn(pThrd, pReq); - // } else { - return cliHandleReq__noShareConn(pThrd, pReq); - //} -} +void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq) { return cliHandleReq__noShareConn(pThrd, pReq); } static void cliDoReq(queue* wq, SCliThrd* pThrd) { int count = 0; @@ -2489,23 +2152,23 @@ static void cliDoBatchReq(queue* wq, SCliThrd* pThrd) { SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - if (pReq->type == Normal && REQUEST_NO_RESP(&pReq->msg)) { - cliBuildBatch(pReq, h, pThrd); - continue; - } + // if (pReq->type == Normal && REQUEST_NO_RESP(&pReq->msg)) { + // cliBuildBatch(pReq, h, pThrd); + // continue; + // } (*cliAsyncHandle[pReq->type])(pThrd, pReq); count++; } - void** pIter = taosHashIterate(pThrd->batchCache, NULL); - while (pIter != NULL) { - SCliBatchList* batchList = (SCliBatchList*)(*pIter); - SCliBatch* batch = cliGetHeadFromList(batchList); - if (batch != NULL) { - cliHandleBatchReq(batch, pThrd); - } - pIter = (void**)taosHashIterate(pThrd->batchCache, pIter); - } + // void** pIter = taosHashIterate(pThrd->batchCache, NULL); + // while (pIter != NULL) { + // SCliBatchList* batchList = (SCliBatchList*)(*pIter); + // SCliBatch* batch = cliGetHeadFromList(batchList); + // if (batch != NULL) { + // cliHandleBatchReq(batch, pThrd); + // } + // pIter = (void**)taosHashIterate(pThrd->batchCache, pIter); + // } if (count >= 2) { tTrace("cli process batch size:%d", count); @@ -2555,6 +2218,20 @@ void cliConnFreeMsgs(SCliConn* conn) { cmsg->ctx->ahandle = NULL; } } + +bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead) { + if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { + for (int i = 0; i < transQueueSize(&conn->reqs); i++) { + SCliReq* pReq = transQueueGet(&conn->reqs, i); + if (pHead->ahandle == (uint64_t)pReq->ctx->ahandle) { + tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, conn->refId); + transQueueRm(&conn->reqs, i); + return true; + } + } + } + return false; +} bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { uint64_t ahandle = pHead->ahandle; @@ -3778,7 +3455,6 @@ int32_t transSetDefaultAddr(void* pInstRef, const char* ip, const char* fqdn) { pReq->ctx = pCtx; pReq->type = Update; - // pReq->refId = (int64_t)pInstRef; SCliThrd* thrd = ((SCliObj*)pInst->tcphandle)->pThreadObj[i]; tDebug("%s update epset at thread:%08" PRId64, pInst->label, thrd->pid); @@ -3898,7 +3574,10 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { if (code != 0) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; + } else { + tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); } + return pConn; } static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { @@ -3908,7 +3587,9 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { if (code != 0) { return code; } - return transHeapInsert(p, pConn); + code = transHeapInsert(p, pConn); + tDebug("add conn %p to heap cache for key:%s,status:%d, refCnt:%d", pConn, pConn->dstAddr, pConn->inHeap, + pConn->reqRefCnt); } static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { @@ -3961,7 +3642,9 @@ int32_t transHeapGet(SHeap* heap, SCliConn** p) { } int32_t transHeapInsert(SHeap* heap, SCliConn* p) { // impl later + p->reqRefCnt++; if (p->inHeap == 1) { + tDebug("failed to insert conn %p since already in heap", p); return TSDB_CODE_DUP_KEY; } @@ -3972,8 +3655,18 @@ int32_t transHeapInsert(SHeap* heap, SCliConn* p) { int32_t transHeapDelete(SHeap* heap, SCliConn* p) { // impl later if (p->inHeap == 0) { + tDebug("failed to del conn %p since not in heap", p); return TSDB_CODE_INVALID_PARA; } - heapRemove(heap->heap, &p->node); + p->inHeap = 0; + p->reqRefCnt--; + if (p->reqRefCnt == 0) { + heapRemove(heap->heap, &p->node); + tDebug("delete conn %p delete from heap", p); + } else if (p->reqRefCnt < 0) { + tDebug("conn %p has %d reqs, not delete from heap,assert", p, p->reqRefCnt); + } else { + tDebug("conn %p has %d reqs, not delete from heap", p, p->reqRefCnt); + } return 0; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 6b5c15eae3..27a92fb483 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -662,21 +662,22 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { return TSDB_CODE_INVALID_MSG; } - if (pConn->status == ConnNormal) { - pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); - if (smsg->type == Release) pHead->msgType = 0; - } else { - if (smsg->type == Release) { - pHead->msgType = 0; - pConn->status = ConnNormal; - destroyConnRegArg(pConn); - transUnrefSrvHandle(pConn); - } else { - // set up resp msg type - pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); - } - } + // if (pConn->status == ConnNormal) { + // pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); + // if (smsg->type == Release) pHead->msgType = 0; + // } else { + // if (smsg->type == Release) { + // pHead->msgType = 0; + // pConn->status = ConnNormal; + // destroyConnRegArg(pConn); + // transUnrefSrvHandle(pConn); + // } else { + // // set up resp msg type + // pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); + // } + // } + pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); pHead->release = smsg->type == Release ? 1 : 0; pHead->code = htonl(pMsg->code); pHead->msgLen = htonl(pMsg->contLen + sizeof(STransMsgHead)); @@ -835,13 +836,13 @@ static void uvShutDownCb(uv_shutdown_t* req, int status) { } static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { if ((pHead)->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { - int32_t code = reallocConnRef(pConn); - if (code != 0) { - destroyConn(pConn, true); - return true; - } - tTrace("conn %p received release request", 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; (void)transClearBuffer(&pConn->readBuf); transFreeMsg(transContFromHead((char*)pHead)); @@ -850,7 +851,11 @@ static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { } pConn->status = ConnRelease; - STransMsg tmsg = {.code = 0, .info.handle = (void*)pConn, .info.traceId = traceId, .info.ahandle = (void*)0x9527}; + STransMsg tmsg = {.code = 0, + .info.handle = (void*)pConn, + .info.traceId = traceId, + .info.ahandle = (void*)0x9527, + .info.seqNum = htonl(pHead->seqNum)}; SSvrMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrMsg)); srvMsg->msg = tmsg; srvMsg->type = Release; @@ -1590,11 +1595,6 @@ void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd) { int32_t code = 0; SSvrConn* conn = msg->pConn; if (conn->status == ConnAcquire) { - code = reallocConnRef(conn); - if (code != 0) { - destroyConn(conn, true); - return; - } if (!transQueuePush(&conn->srvMsgs, msg)) { return; } From ab66eefcb4405c0af915a76dfd1808f85dcb0596 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 4 Sep 2024 18:55:02 +0800 Subject: [PATCH 048/240] refactor transport --- source/libs/transport/src/transCli.c | 54 ++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4a7cf8da42..70d4d43f09 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1064,20 +1064,13 @@ static void addConnToPool(void* pool, SCliConn* conn) { uv_read_stop(conn->stream); conn->seq = 0; - int32_t code = allocConnRef(conn, true); - if (code != 0) { - cliDestroyConn(conn, true); - return; - } SCliThrd* thrd = conn->hostThrd; cliResetConnTimer(conn); if (T_REF_VAL_GET(conn) > 1) { transUnrefCliHandle(conn); } - cliDestroyConnMsgs(conn, false); - conn->seq = 0; if (conn->list == NULL && conn->dstAddr != NULL) { conn->list = taosHashGet((SHashObj*)pool, conn->dstAddr, strlen(conn->dstAddr)); @@ -1248,7 +1241,6 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); - // TAOS_CHECK_GOTO(addConnToHeapCache(pThrd->connHeapCache, pConn), NULL, _exception); transQueuePush(&pConn->reqs, pReq); @@ -1332,7 +1324,44 @@ _failed: taosMemoryFree(conn); return code; } -static void cliDestroyConn(SCliConn* conn, bool clear) {} +static void cliDestroyConn(SCliConn* conn, bool clear) { + SCliThrd* pThrd = conn->hostThrd; + tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn); + conn->broken = true; + QUEUE_REMOVE(&conn->q); + QUEUE_INIT(&conn->q); + + conn->broken = true; + if (conn->list == NULL) { + conn->list = taosHashGet((SHashObj*)pThrd->pool, conn->dstAddr, strlen(conn->dstAddr)); + } + + if (conn->list) { + SConnList* list = conn->list; + list->list->numOfConn--; + if (conn->status == ConnInPool) { + list->size--; + } + } + conn->list = NULL; + + (void)transReleaseExHandle(transGetRefMgt(), conn->refId); + (void)transRemoveExHandle(transGetRefMgt(), conn->refId); + conn->refId = -1; + + if (conn->task != NULL) { + transDQCancel(pThrd->timeoutQueue, conn->task); + conn->task = NULL; + } + // cliResetTimer(pThrd, conn); + + if (clear) { + if (!uv_is_closing((uv_handle_t*)conn->stream)) { + (void)uv_read_stop(conn->stream); + uv_close((uv_handle_t*)conn->stream, cliDestroy); + } + } +} static void cliDestroy(uv_handle_t* handle) { if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) { return; @@ -1350,6 +1379,8 @@ static void cliDestroy(uv_handle_t* handle) { cliDestroyConnMsgs(conn, true); + delConnFromHeapCache(pThrd->connHeapCache, conn); + tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); transReqQueueClear(&conn->wreqQueue); (void)transDestroyBuffer(&conn->readBuf); @@ -1435,7 +1466,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int32_t totalLen = 0; if (size == 0) { - tError("%s conn %p not msg to send", pInst->label, pConn); + tDebug("%s conn %p not msg to send", pInst->label, pConn); return; } uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); @@ -3590,6 +3621,7 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { code = transHeapInsert(p, pConn); tDebug("add conn %p to heap cache for key:%s,status:%d, refCnt:%d", pConn, pConn->dstAddr, pConn->inHeap, pConn->reqRefCnt); + return code; } static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { @@ -3656,7 +3688,7 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { // impl later if (p->inHeap == 0) { tDebug("failed to del conn %p since not in heap", p); - return TSDB_CODE_INVALID_PARA; + return 0; } p->inHeap = 0; p->reqRefCnt--; From 39409971946faf81e73b7dcf5da08b0ace93497f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 5 Sep 2024 11:29:43 +0800 Subject: [PATCH 049/240] refactor transport --- source/libs/transport/src/transCli.c | 47 +++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 70d4d43f09..c3808fba58 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -66,6 +66,7 @@ typedef struct SCliConn { SConnBuffer readBuf; STransQueue reqs; + SHashObj* pQueryTable; queue q; SConnList* list; @@ -109,6 +110,8 @@ typedef struct SCliReq { int sent; //(0: no send, 1: alread sent) queue seqq; int32_t seq; + + queue qlist; } SCliReq; typedef struct SCliThrd { @@ -1234,6 +1237,27 @@ static int32_t cliRmReqFromConn(SCliConn* conn, SCliReq** pReq) { } return 0; } +static int32_t cliPutQReqToTable(SCliConn* pConn, SCliReq* pReq) { + int32_t code = 0; + if (pReq->msg.info.handle == 0) { + return 0; + } + + queue q; + QUEUE_INIT(&q); + + queue* p = taosHashGet(pConn->pQueryTable, (void*)pReq->msg.info.handle, sizeof(int64_t)); + if (p == NULL) { + QUEUE_PUSH(&q, &pReq->qlist); + code = taosHashPut(pConn->pQueryTable, (void*)pReq->msg.info.handle, sizeof(int64_t), &q, sizeof(queue)); + if (code != 0) { + return code; + } + } else { + QUEUE_PUSH(p, &pReq->qlist); + } + return 0; +} static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) { int32_t code = 0; SCliConn* pConn = NULL; @@ -1242,6 +1266,12 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); + if (pReq->msg.info.handle != 0) { + // SExHandle *p = transAcquireExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); + // TAOS_CHECK_GOTO(specifyConnRef(pConn, false, pReq->msg.info.handle), NULL, _exception); + // } else { + // TAOS_CHECK_GOTO(allocConnRef(pConn, false), NULL, _exception); + } transQueuePush(&pConn->reqs, pReq); return cliDoConn(pThrd, pConn); @@ -1271,6 +1301,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int conn->status = ConnNormal; conn->broken = false; + conn->pQueryTable = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); TAOS_CHECK_GOTO(transQueueInit(&conn->reqs, NULL), NULL, _failed); TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); @@ -1701,7 +1732,7 @@ void cliConnCb(uv_connect_t* req, int status) { // } else if (timeout == true) { // // already deal by timeout // } - // return; + return; } cliConnSetSockInfo(pConn); @@ -1974,6 +2005,20 @@ static void doFreeTimeoutMsg(void* param) { taosMemoryFree(arg); } +int32_t cliConnHandleQueryById(SCliReq* pReq) { + if (pReq->msg.info.handle == 0) { + return 0; + } else { + int64_t queryId = (int64_t)pReq->msg.info.handle; + SExHandle* exh = transAcquireExHandle(transGetRefMgt(), queryId); + if (exh->inited == 1) { + + } else { + } + transReleaseExHandle(transGetRefMgt(), queryId); + } + return 0; +} void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { int32_t lino = 0; STransMsg resp = {0}; From f797c8ed2e9b5a6cccf79c35bee1d86d3672ce0f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Sep 2024 21:53:52 +0800 Subject: [PATCH 050/240] opt transport --- include/libs/transport/trpc.h | 4 +- source/libs/transport/inc/transComm.h | 7 +- source/libs/transport/src/transSvr.c | 230 ++++++++++---------------- 3 files changed, 97 insertions(+), 144 deletions(-) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index cc9d789430..c1265d768c 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -63,7 +63,9 @@ typedef struct SRpcHandleInfo { int8_t forbiddenIp; int8_t notFreeAhandle; int8_t compressed; - int32_t seqNum; + int32_t seqNum; // msg seq + int64_t qId; // queryId Get from client, other req's qId = -1; + int32_t refIdMgt; } SRpcHandleInfo; typedef struct SRpcMsg { diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 9ab2d918b8..df7b4f8fcf 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -183,7 +183,8 @@ typedef struct { uint32_t magicNum; STraceId traceId; uint64_t ahandle; // ahandle assigned by client - uint32_t code; // del later + int64_t qid; + uint32_t code; // del later uint32_t msgType; int32_t msgLen; int32_t seqNum; @@ -272,10 +273,10 @@ bool transAsyncPoolIsEmpty(SAsyncPool* pool); } \ } while (0) -#define ASYNC_CHECK_HANDLE(exh1, id) \ +#define ASYNC_CHECK_HANDLE(idMgt, id, exh1) \ do { \ if (id > 0) { \ - SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), id); \ + SExHandle* exh2 = transAcquireExHandle(idMgt, id); \ 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); \ diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 27a92fb483..85d064b68f 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -58,6 +58,9 @@ typedef struct SSvrConn { char ckey[TSDB_PASSWORD_LEN]; // ciphering key int64_t whiteListVer; + + // state req dict + SHashObj* pQTable; } SSvrConn; typedef struct SSvrMsg { @@ -98,6 +101,8 @@ typedef struct SWorkThrd { SIpWhiteListTab* pWhiteList; int64_t whiteListVer; int8_t enableIpWhiteList; + + int32_t connRefMgt; } SWorkThrd; typedef struct SServerObj { @@ -166,6 +171,8 @@ static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn); static int32_t reallocConnRef(SSvrConn* conn); +int32_t uvGetConnRefOfThrd(SWorkThrd* thrd) { return thrd ? thrd->connRefMgt : -1; } + static void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd); static void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd); static void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd); @@ -447,6 +454,7 @@ static bool uvHandleReq(SSvrConn* pConn) { tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); return false; } + pHead->ahandle = htole64(pHead->ahandle); pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); @@ -470,18 +478,29 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.pCont = pHead->content; transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; + transMsg.info.qId = htole64(pHead->qid); + + if (transMsg.info.qId > 0) { + int32_t code = taosHashPut(pConn->pQTable, &transMsg.info.qId, sizeof(int64_t), &transMsg, sizeof(STransMsg)); + if (code != 0) { + tError("%s conn %p failed to put msg to req dict, since %s", transLabel(pInst), pConn, tstrerror(code)); + return false; + } + } if (pHead->seqNum == 0) { ASSERT(0); } + + transMsg.info.handle = (void*)transAcquireExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId); + transMsg.info.refIdMgt = pThrd->connRefMgt; + + ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg"); + // pHead->noResp = 1, // 1. server application should not send resp on handle // 2. once send out data, cli conn released to conn pool immediately // 3. not mixed with persist - transMsg.info.ahandle = (void*)pHead->ahandle; - transMsg.info.handle = (void*)transAcquireExHandle(transGetRefMgt(), pConn->refId); - ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg"); - transMsg.info.refId = pHead->noResp == 1 ? -1 : pConn->refId; transMsg.info.traceId = pHead->traceId; transMsg.info.cliVer = htonl(pHead->compatibilityVer); @@ -489,7 +508,7 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.info.noResp = pHead->noResp == 1 ? 1 : 0; transMsg.info.seqNum = htonl(pHead->seqNum); - uvMaySetConnAcquired(pConn, pHead); + // uvMaySetConnAcquired(pConn, pHead); uvPerfLog_receive(pConn, pHead, &transMsg); @@ -499,7 +518,7 @@ static bool uvHandleReq(SSvrConn* pConn) { pConnInfo->clientPort = pConn->port; tstrncpy(pConnInfo->user, pConn->user, sizeof(pConnInfo->user)); - (void)transReleaseExHandle(transGetRefMgt(), pConn->refId); + (void)transReleaseExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId); (*pInst->cfp)(pInst->parent, &transMsg, NULL); return true; @@ -647,7 +666,7 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { pMsg->contLen = 0; } STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); - pHead->ahandle = (uint64_t)pMsg->info.ahandle; + // pHead->ahandle = (uint64_t)pMsg->info.ahandle; pHead->traceId = pMsg->info.traceId; pHead->hasEpSet = pMsg->info.hasEpSet; pHead->magicNum = htonl(TRANS_MAGIC_NUM); @@ -798,15 +817,15 @@ void uvWorkerAsyncCb(uv_async_t* handle) { int64_t refId = transMsg.info.refId; msg->seqNum = transMsg.info.seqNum; - SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), refId); + SExHandle* exh2 = transAcquireExHandle(uvGetConnRefOfThrd(pThrd), refId); if (exh2 == NULL || exh1 != exh2) { tTrace("handle except msg %p, ignore it", exh1); - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(uvGetConnRefOfThrd(pThrd), refId); destroySmsg(msg); continue; } msg->pConn = exh1->handle; - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(uvGetConnRefOfThrd(pThrd), refId); (*transAsyncHandle[msg->type])(msg, pThrd); } } @@ -836,12 +855,6 @@ static void uvShutDownCb(uv_shutdown_t* req, int status) { } static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { if ((pHead)->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { - // int32_t code = reallocConnRef(pConn); - - // if (code != 0) { - // destroyConn(pConn, true); - // return true; - // } tTrace("conn %p received release request", pConn); STraceId traceId = pHead->traceId; (void)transClearBuffer(&pConn->readBuf); @@ -874,53 +887,6 @@ static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { } return false; } -static void uvPrepareCb(uv_prepare_t* handle) { - // prepare callback - SWorkThrd* pThrd = handle->data; - SAsyncPool* pool = pThrd->asyncPool; - - for (int i = 0; i < pool->nAsync; i++) { - uv_async_t* async = &(pool->asyncs[i]); - SAsyncItem* item = async->data; - - queue wq; - (void)taosThreadMutexLock(&item->mtx); - QUEUE_MOVE(&item->qmsg, &wq); - (void)taosThreadMutexUnlock(&item->mtx); - - while (!QUEUE_IS_EMPTY(&wq)) { - queue* head = QUEUE_HEAD(&wq); - QUEUE_REMOVE(head); - - SSvrMsg* msg = QUEUE_DATA(head, SSvrMsg, q); - if (msg == NULL) { - tError("unexcept occurred, continue"); - continue; - } - // release handle to rpc init - if (msg->type == Quit || msg->type == Update) { - (*transAsyncHandle[msg->type])(msg, pThrd); - continue; - } else { - STransMsg transMsg = msg->msg; - - SExHandle* exh1 = transMsg.info.handle; - int64_t refId = transMsg.info.refId; - SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), refId); - if (exh2 == NULL || exh1 != exh2) { - tTrace("handle except msg %p, ignore it", exh1); - (void)transReleaseExHandle(transGetRefMgt(), refId); - destroySmsg(msg); - continue; - } - msg->pConn = exh1->handle; - (void)transReleaseExHandle(transGetRefMgt(), refId); - (*transAsyncHandle[msg->type])(msg, pThrd); - } - } - } -} - static void uvWorkDoTask(uv_work_t* req) { // doing time-consumeing task // only auth conn currently, add more func later @@ -1011,7 +977,6 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { } if (pThrd->quit) { tWarn("thread already received quit msg, ignore incoming conn"); - // uv_close((uv_handle_t*)q, NULL); return; } @@ -1022,16 +987,6 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { return; } - // pConn->pInst = pThrd->pInst; - // /* 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; (void)uv_fileno((const uv_handle_t*)pConn->pTcp, &fd); @@ -1122,25 +1077,6 @@ static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { QUEUE_INIT(&pThrd->msg); - pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t)); - 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); @@ -1244,14 +1180,14 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { exh->handle = pConn; exh->pThrd = pThrd; - exh->refId = transAddExHandle(transGetRefMgt(), exh); + exh->refId = transAddExHandle(uvGetConnRefOfThrd(pThrd), exh); if (exh->refId < 0) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, &lino, _end); } QUEUE_INIT(&exh->q); - SExHandle* pSelf = transAcquireExHandle(transGetRefMgt(), exh->refId); + SExHandle* pSelf = transAcquireExHandle(uvGetConnRefOfThrd(pThrd), exh->refId); if (pSelf != exh) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _end); } @@ -1263,11 +1199,11 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { transRefSrvHandle(pConn); tTrace("%s handle %p, conn %p created, refId:%" PRId64, transLabel(pInst), exh, pConn, pConn->refId); - pConn->pInst = pThrd->pInst; - /* init conn timer*/ - // uv_timer_init(pThrd->loop, &pConn->pTimer); - // pConn->pTimer.data = pConn; - pConn->hostThrd = pThrd; + pConn->pQTable = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + if (pConn->pQTable == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); + } + // init client handle pConn->pTcp = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); if (pConn->pTcp == NULL) { @@ -1282,11 +1218,15 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { pConn->pTcp->data = pConn; QUEUE_PUSH(&pThrd->conn, &pConn->queue); + pConn->pInst = pThrd->pInst; + pConn->hostThrd = pThrd; + return pConn; _end: if (pConn) { transQueueDestroy(&pConn->srvMsgs); (void)transDestroyBuffer(&pConn->readBuf); + taosHashCleanup(pConn->pQTable); taosMemoryFree(pConn->pTcp); taosMemoryFree(pConn); pConn = NULL; @@ -1315,8 +1255,8 @@ static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn) { } static int32_t reallocConnRef(SSvrConn* conn) { if (conn->refId > 0) { - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); + (void)transReleaseExHandle(uvGetConnRefOfThrd(conn->hostThrd), conn->refId); + (void)transRemoveExHandle(uvGetConnRefOfThrd(conn->hostThrd), conn->refId); } // avoid app continue to send msg on invalid handle SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle)); @@ -1326,14 +1266,14 @@ static int32_t reallocConnRef(SSvrConn* conn) { exh->handle = conn; exh->pThrd = conn->hostThrd; - exh->refId = transAddExHandle(transGetRefMgt(), exh); + exh->refId = transAddExHandle(uvGetConnRefOfThrd(conn->hostThrd), exh); if (exh->refId < 0) { taosMemoryFree(exh); return TSDB_CODE_REF_INVALID_ID; } QUEUE_INIT(&exh->q); - SExHandle* pSelf = transAcquireExHandle(transGetRefMgt(), exh->refId); + SExHandle* pSelf = transAcquireExHandle(uvGetConnRefOfThrd(conn->hostThrd), exh->refId); if (pSelf != exh) { tError("conn %p failed to acquire handle", conn); taosMemoryFree(exh); @@ -1352,8 +1292,8 @@ static void uvDestroyConn(uv_handle_t* handle) { } SWorkThrd* thrd = conn->hostThrd; - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); + (void)transReleaseExHandle(uvGetConnRefOfThrd(thrd), conn->refId); + (void)transRemoveExHandle(uvGetConnRefOfThrd(thrd), conn->refId); STrans* pInst = thrd->pInst; tDebug("%s conn %p destroy", transLabel(pInst), conn); @@ -1366,6 +1306,8 @@ static void uvDestroyConn(uv_handle_t* handle) { transReqQueueClear(&conn->wreqQueue); QUEUE_REMOVE(&conn->queue); + + taosHashCleanup(conn->pQTable); taosMemoryFree(conn->pTcp); destroyConnRegArg(conn); (void)transDestroyBuffer(&conn->readBuf); @@ -1512,6 +1454,12 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, goto End; } + thrd->connRefMgt = transOpenRefMgt(50000, transDestroyExHandle); + if (thrd->connRefMgt < 0) { + code = thrd->connRefMgt; + goto End; + } + srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); if (srv->pipe[i] == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -1603,6 +1551,7 @@ void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd) { } else if (conn->status == ConnRelease || conn->status == ConnNormal) { tDebug("%s conn %p already released, ignore release-msg", transLabel(thrd->pInst), conn); } + destroySmsg(msg); } void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd) { @@ -1610,32 +1559,30 @@ void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd) { tDebug("%s conn %p start to send resp (2/2)", transLabel(thrd->pInst), msg->pConn); uvStartSendResp(msg); } + +int32_t uvHandleStateReq(SSvrMsg* msg) { + int32_t code = 0; + SSvrConn* conn = msg->pConn; + tDebug("%s conn %p start to register brokenlink callback, qid:%" PRId64 "", transLabel(conn->pInst), conn, + msg->msg.info.qId); + + SSvrRegArg arg = {.notifyCount = 0, .init = 1, .msg = msg->msg}; + SSvrRegArg* p = taosHashGet(conn->pQTable, &msg->msg.info.qId, sizeof(msg->msg.info.qId)); + if (p != NULL) { + transFreeMsg(p->msg.pCont); + } + + code = taosHashPut(conn->pQTable, &msg->msg.info.qId, sizeof(msg->msg.info.qId), &arg, sizeof(arg)); + if (code == 0) tDebug("conn %p register brokenlink callback succ", conn); + return code; +} void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd) { SSvrConn* conn = msg->pConn; tDebug("%s conn %p register brokenlink callback", transLabel(thrd->pInst), conn); - if (conn->status == ConnAcquire) { - if (!transQueuePush(&conn->srvMsgs, msg)) { - return; - } - (void)transQueuePop(&conn->srvMsgs); - - if (conn->regArg.init) { - transFreeMsg(conn->regArg.msg.pCont); - conn->regArg.init = 0; - } - conn->regArg.notifyCount = 0; - conn->regArg.init = 1; - conn->regArg.msg = msg->msg; - tDebug("conn %p register brokenlink callback succ", conn); - - if (conn->broken) { - STrans* pInst = conn->pInst; - (*pInst->cfp)(pInst->parent, &(conn->regArg.msg), NULL); - memset(&conn->regArg, 0, sizeof(conn->regArg)); - } - taosMemoryFree(msg); - } + int32_t code = uvHandleStateReq(msg); + taosMemoryFree(msg); } + void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) { SUpdateIpWhite* req = msg->arg; if (req == NULL) { @@ -1752,7 +1699,7 @@ int32_t transReleaseSrvHandle(void* handle) { SExHandle* exh = info->handle; int64_t refId = info->refId; - ASYNC_CHECK_HANDLE(exh, refId); + ASYNC_CHECK_HANDLE(info->refIdMgt, refId, exh); SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); @@ -1771,15 +1718,15 @@ int32_t transReleaseSrvHandle(void* handle) { tDebug("%s conn %p start to release", transLabel(pThrd->pInst), exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(info->refIdMgt, refId); return code; } - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(info->refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to send to release handle", exh); - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(info->refIdMgt, refId); return code; _return2: tDebug("handle %p failed to send to release handle", exh); @@ -1801,7 +1748,7 @@ int32_t transSendResponse(const STransMsg* msg) { return 0; } int64_t refId = msg->info.refId; - ASYNC_CHECK_HANDLE(exh, refId); + ASYNC_CHECK_HANDLE(msg->info.refIdMgt, refId, exh); STransMsg tmsg = *msg; tmsg.info.refId = refId; @@ -1822,17 +1769,17 @@ int32_t transSendResponse(const STransMsg* msg) { tGDebug("conn %p start to send resp (1/2)", exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(msg->info.refIdMgt, refId); return code; } - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(msg->info.refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to send resp", exh); rpcFreeCont(msg->pCont); - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(msg->info.refIdMgt, refId); return code; _return2: tDebug("handle %p failed to send resp", exh); @@ -1844,12 +1791,15 @@ int32_t transRegisterMsg(const STransMsg* msg) { SExHandle* exh = msg->info.handle; int64_t refId = msg->info.refId; - ASYNC_CHECK_HANDLE(exh, refId); + ASYNC_CHECK_HANDLE(msg->info.refIdMgt, refId, exh); STransMsg tmsg = *msg; tmsg.info.noResp = 1; + tmsg.info.qId = msg->info.qId; + tmsg.info.seqNum = msg->info.seqNum; tmsg.info.refId = refId; + tmsg.info.refIdMgt = msg->info.refIdMgt; SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); @@ -1867,17 +1817,17 @@ int32_t transRegisterMsg(const STransMsg* msg) { tDebug("%s conn %p start to register brokenlink callback", transLabel(pInst), exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(msg->info.refIdMgt, refId); return code; } - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(msg->info.refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to register brokenlink", exh); rpcFreeCont(msg->pCont); - (void)transReleaseExHandle(transGetRefMgt(), refId); + (void)transReleaseExHandle(msg->info.refIdMgt, refId); return code; _return2: tDebug("handle %p failed to register brokenlink", exh); From 94891d5bffafee25e87b516f8876eb61c4d7c7e9 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 7 Sep 2024 17:29:35 +0800 Subject: [PATCH 051/240] opt transport --- include/common/tmsgdef.h | 1 + include/util/taoserror.h | 4 + source/client/src/clientImpl.c | 11 +- source/client/src/clientMain.c | 80 ++--- source/client/src/clientMonitor.c | 34 +-- source/client/src/clientTmq.c | 238 ++++++++------- source/libs/catalog/src/ctgRemote.c | 75 ++--- source/libs/executor/src/dataInserter.c | 24 +- source/libs/executor/src/sysscanoperator.c | 3 +- source/libs/scheduler/src/schRemote.c | 3 +- source/libs/transport/inc/transComm.h | 1 + source/libs/transport/src/transCli.c | 337 +++++++++------------ source/libs/transport/src/transSvr.c | 238 ++++++++------- source/util/src/terror.c | 1 + 14 files changed, 522 insertions(+), 528 deletions(-) diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 572e26bc62..ff524faefd 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -323,6 +323,7 @@ TD_DEF_MSG_TYPE(TDMT_SCH_EXPLAIN, "explain", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "link-broken", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SCH_TASK_NOTIFY, "task-notify", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_SCH_TASK_RELEASE, "task-release", NULL, NULL) TD_CLOSE_MSG_SEG(TDMT_SCH_MSG) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index a084f7b2f5..534f7d0505 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -93,6 +93,10 @@ int32_t taosGetErrSize(); #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) #define TSDB_CODE_RPC_ASYNC_IN_PROCESS TAOS_DEF_ERROR_CODE(0, 0x0028) +#define TSDB_CODE_RPC_NO_STATE TAOS_DEF_ERROR_CODE(0, 0x0029) + + + diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 6b8bf88030..008338d043 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -335,8 +335,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { STscObj* pTscObj = pRequest->pTscObj; SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest); - int64_t transporterId = 0; - TSC_ERR_RET(asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg)); + TSC_ERR_RET(asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, NULL, pSendMsg)); (void)tsem_wait(&pRequest->body.rspSem); return TSDB_CODE_SUCCESS; } @@ -392,8 +391,7 @@ int32_t asyncExecDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { SAppInstInfo* pAppInfo = getAppInfo(pRequest); SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest); - int64_t transporterId = 0; - int32_t code = asyncSendMsgToServer(pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg); + int32_t code = asyncSendMsgToServer(pAppInfo->pTransporter, &pMsgInfo->epSet, NULL, pSendMsg); if (code) { doRequestCallback(pRequest, code); } @@ -1557,9 +1555,8 @@ int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __ta return code; } - int64_t transporterId = 0; - code = asyncSendMsgToServer((*pTscObj)->pAppInfo->pTransporter, &(*pTscObj)->pAppInfo->mgmtEp.epSet, &transporterId, - body); + // int64_t transporterId = 0; + code = asyncSendMsgToServer((*pTscObj)->pAppInfo->pTransporter, &(*pTscObj)->pAppInfo->mgmtEp.epSet, NULL, body); if (TSDB_CODE_SUCCESS != code) { destroyTscObj(*pTscObj); tscError("failed to send connect msg to server, code:%s", tstrerror(code)); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index de56a4844a..59351d66d7 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -16,19 +16,19 @@ #include "catalog.h" #include "clientInt.h" #include "clientLog.h" -#include "clientStmt.h" #include "clientMonitor.h" +#include "clientStmt.h" #include "functionMgt.h" #include "os.h" #include "query.h" #include "scheduler.h" +#include "tcompare.h" #include "tdatablock.h" #include "tglobal.h" #include "tmsg.h" #include "tref.h" #include "trpc.h" #include "version.h" -#include "tcompare.h" #define TSC_VAR_NOT_RELEASE 1 #define TSC_VAR_RELEASED 0 @@ -120,7 +120,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha } STscObj *pObj = NULL; - int32_t code = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY, &pObj); + int32_t code = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY, &pObj); if (TSDB_CODE_SUCCESS == code) { int64_t *rid = taosMemoryCalloc(1, sizeof(int64_t)); if (NULL == rid) { @@ -183,15 +183,15 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type) return 0; } -typedef struct SFetchWhiteListInfo{ - int64_t connId; +typedef struct SFetchWhiteListInfo { + int64_t connId; __taos_async_whitelist_fn_t userCbFn; - void* userParam; + void *userParam; } SFetchWhiteListInfo; -int32_t fetchWhiteListCallbackFn(void* param, SDataBuf* pMsg, int32_t code) { - SFetchWhiteListInfo* pInfo = (SFetchWhiteListInfo*)param; - TAOS* taos = &pInfo->connId; +int32_t fetchWhiteListCallbackFn(void *param, SDataBuf *pMsg, int32_t code) { + SFetchWhiteListInfo *pInfo = (SFetchWhiteListInfo *)param; + TAOS *taos = &pInfo->connId; if (code != TSDB_CODE_SUCCESS) { pInfo->userCbFn(pInfo->userParam, code, taos, 0, NULL); taosMemoryFree(pMsg->pData); @@ -209,7 +209,7 @@ int32_t fetchWhiteListCallbackFn(void* param, SDataBuf* pMsg, int32_t code) { return terrno; } - uint64_t* pWhiteLists = taosMemoryMalloc(wlRsp.numWhiteLists * sizeof(uint64_t)); + uint64_t *pWhiteLists = taosMemoryMalloc(wlRsp.numWhiteLists * sizeof(uint64_t)); if (pWhiteLists == NULL) { taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); @@ -238,7 +238,7 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa return; } - int64_t connId = *(int64_t*)taos; + int64_t connId = *(int64_t *)taos; STscObj *pTsc = acquireTscObj(connId); if (NULL == pTsc) { @@ -255,7 +255,7 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa return; } - void* pReq = taosMemoryMalloc(msgLen); + void *pReq = taosMemoryMalloc(msgLen); if (pReq == NULL) { fp(param, TSDB_CODE_OUT_OF_MEMORY, taos, 0, NULL); releaseTscObj(connId); @@ -269,7 +269,7 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa return; } - SFetchWhiteListInfo* pParam = taosMemoryMalloc(sizeof(SFetchWhiteListInfo)); + SFetchWhiteListInfo *pParam = taosMemoryMalloc(sizeof(SFetchWhiteListInfo)); if (pParam == NULL) { fp(param, TSDB_CODE_OUT_OF_MEMORY, taos, 0, NULL); taosMemoryFree(pReq); @@ -280,9 +280,9 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa pParam->connId = connId; pParam->userCbFn = fp; pParam->userParam = param; - SMsgSendInfo* pSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); + SMsgSendInfo *pSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (pSendInfo == NULL) { - fp(param, TSDB_CODE_OUT_OF_MEMORY, taos, 0, NULL); + fp(param, TSDB_CODE_OUT_OF_MEMORY, taos, 0, NULL); taosMemoryFree(pParam); taosMemoryFree(pReq); releaseTscObj(connId); @@ -296,9 +296,8 @@ void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *pa pSendInfo->fp = fetchWhiteListCallbackFn; pSendInfo->msgType = TDMT_MND_GET_USER_WHITELIST; - int64_t transportId = 0; SEpSet epSet = getEpSet_s(&pTsc->pAppInfo->mgmtEp); - if (TSDB_CODE_SUCCESS != asyncSendMsgToServer(pTsc->pAppInfo->pTransporter, &epSet, &transportId, pSendInfo)) { + if (TSDB_CODE_SUCCESS != asyncSendMsgToServer(pTsc->pAppInfo->pTransporter, &epSet, NULL, pSendInfo)) { tscWarn("failed to async send msg to server"); } releaseTscObj(connId); @@ -443,7 +442,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return NULL; } - if(pRequest->inCallback) { + if (pRequest->inCallback) { tscError("can not call taos_fetch_row before query callback ends."); terrno = TSDB_CODE_TSC_INVALID_OPERATION; return NULL; @@ -454,7 +453,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { SMqRspObj *msg = ((SMqRspObj *)res); SReqResultInfo *pResultInfo = NULL; if (msg->common.resIter == -1) { - if(tmqGetNextResInfo(res, true, &pResultInfo) != 0){ + if (tmqGetNextResInfo(res, true, &pResultInfo) != 0) { return NULL; } } else { @@ -466,7 +465,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { pResultInfo->current += 1; return pResultInfo->row; } else { - if (tmqGetNextResInfo(res, true, &pResultInfo) != 0){ + if (tmqGetNextResInfo(res, true, &pResultInfo) != 0) { return NULL; } @@ -540,22 +539,23 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) len += sprintf(str + len, "%lf", dv); } break; - case TSDB_DATA_TYPE_VARBINARY:{ - void* data = NULL; + case TSDB_DATA_TYPE_VARBINARY: { + void *data = NULL; uint32_t size = 0; - int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE); - if(taosAscii2Hex(row[i], charLen, &data, &size) < 0){ + int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE); + if (taosAscii2Hex(row[i], charLen, &data, &size) < 0) { break; } (void)memcpy(str + len, data, size); len += size; taosMemoryFree(data); - }break; + } break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_GEOMETRY: { int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE); - if (fields[i].type == TSDB_DATA_TYPE_BINARY || fields[i].type == TSDB_DATA_TYPE_VARBINARY || fields[i].type == TSDB_DATA_TYPE_GEOMETRY) { + if (fields[i].type == TSDB_DATA_TYPE_BINARY || fields[i].type == TSDB_DATA_TYPE_VARBINARY || + fields[i].type == TSDB_DATA_TYPE_GEOMETRY) { if (charLen > fields[i].bytes || charLen < 0) { tscError("taos_print_row error binary. charLen:%d, fields[i].bytes:%d", charLen, fields[i].bytes); break; @@ -664,7 +664,8 @@ const char *taos_get_client_info() { return version; } // return int32_t int taos_affected_rows(TAOS_RES *res) { - if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) { + if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || + TD_RES_TMQ_BATCH_META(res)) { return 0; } @@ -675,7 +676,8 @@ int taos_affected_rows(TAOS_RES *res) { // return int64_t int64_t taos_affected_rows64(TAOS_RES *res) { - if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) { + if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || + TD_RES_TMQ_BATCH_META(res)) { return 0; } @@ -725,7 +727,8 @@ int taos_select_db(TAOS *taos, const char *db) { } void taos_stop_query(TAOS_RES *res) { - if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) { + if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res) || + TD_RES_TMQ_BATCH_META(res)) { return; } @@ -784,7 +787,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { return pRequest->code; } else if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) { SReqResultInfo *pResultInfo = NULL; - int32_t code = tmqGetNextResInfo(res, true, &pResultInfo); + int32_t code = tmqGetNextResInfo(res, true, &pResultInfo); if (code != 0) return code; pResultInfo->current = pResultInfo->numOfRows; @@ -807,7 +810,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) { SReqResultInfo *pResultInfo = NULL; - int32_t code = tmqGetNextResInfo(res, false, &pResultInfo); + int32_t code = tmqGetNextResInfo(res, false, &pResultInfo); if (code != 0) { (*numOfRows) = 0; return 0; @@ -953,7 +956,7 @@ static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t (void)memcpy(&pRequest->parseMeta, pResultMeta, sizeof(*pResultMeta)); (void)memset(pResultMeta, 0, sizeof(*pResultMeta)); } - + handleQueryAnslyseRes(pWrapper, pResultMeta, code); } @@ -999,7 +1002,7 @@ void handleSubQueryFromAnalyse(SSqlCallbackWrapper *pWrapper, SMetaData *pResult } pNewRequest->pQuery = NULL; - code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pNewRequest->pQuery); + code = nodesMakeNode(QUERY_NODE_QUERY, (SNode **)&pNewRequest->pQuery); if (pNewRequest->pQuery) { pNewRequest->pQuery->pRoot = pRoot; pRoot = NULL; @@ -1271,7 +1274,7 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { if (NEED_CLIENT_HANDLE_ERROR(code)) { tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%" PRIx64, pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId); - (void)refreshMeta(pRequest->pTscObj, pRequest); //ignore return code,try again + (void)refreshMeta(pRequest->pTscObj, pRequest); // ignore return code,try again pRequest->prevCode = code; doAsyncQuery(pRequest, true); return; @@ -1285,7 +1288,7 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { void restartAsyncQuery(SRequestObj *pRequest, int32_t code) { tscInfo("restart request: %s p: %p", pRequest->sqlstr, pRequest); - SRequestObj* pUserReq = pRequest; + SRequestObj *pUserReq = pRequest; (void)acquireRequest(pRequest->self); while (pUserReq) { if (pUserReq->self == pUserReq->relation.userRefId || pUserReq->relation.userRefId == 0) { @@ -1631,7 +1634,6 @@ TAOS_STMT *taos_stmt_init_with_options(TAOS *taos, TAOS_STMT_OPTIONS *options) { return pStmt; } - int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length) { if (stmt == NULL || sql == NULL) { tscError("NULL parameter for %s", __FUNCTION__); @@ -1874,7 +1876,7 @@ int taos_stmt_close(TAOS_STMT *stmt) { return stmtClose(stmt); } -int taos_set_conn_mode(TAOS* taos, int mode, int value) { +int taos_set_conn_mode(TAOS *taos, int mode, int value) { if (taos == NULL) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -1897,6 +1899,4 @@ int taos_set_conn_mode(TAOS* taos, int mode, int value) { return 0; } -char* getBuildInfo(){ - return buildinfo; -} +char *getBuildInfo() { return buildinfo; } diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 4bb29f8d97..d7b169399c 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -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; } @@ -161,10 +161,9 @@ static int32_t sendReport(void* pTransporter, SEpSet* epSet, char* pCont, MONITO pInfo->requestId = tGenIdPI64(); pInfo->requestObjRefId = 0; - int64_t transporterId = 0; - return asyncSendMsgToServer(pTransporter, epSet, &transporterId, pInfo); + return asyncSendMsgToServer(pTransporter, epSet, NULL, pInfo); - FAILED: +FAILED: monitorFreeSlowLogDataEx(param); return TAOS_GET_TERRNO(TSDB_CODE_TSC_INTERNAL_ERROR); } @@ -279,7 +278,7 @@ void monitorCreateClient(int64_t clusterId) { return; - fail: +fail: destroyMonitorClient(&pMonitor); taosWUnLockLatch(&monitorLock); } @@ -295,7 +294,7 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* taos_counter_t* newCounter = taos_counter_new(name, help, label_key_count, label_keys); if (newCounter == NULL) return; MonitorClient* pMonitor = *ppMonitor; - if (taos_collector_add_metric(pMonitor->colector, newCounter) != 0){ + if (taos_collector_add_metric(pMonitor->colector, newCounter) != 0) { tscError("failed to add metric to collector"); (void)taos_counter_destroy(newCounter); goto end; @@ -308,7 +307,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); } @@ -331,13 +330,13 @@ void monitorCounterInc(int64_t clusterId, const char* counterName, const char** tscError("monitorCounterInc not found pCounter %" PRIx64 ":%s.", clusterId, counterName); goto end; } - if (taos_counter_inc(*ppCounter, label_values) != 0){ + if (taos_counter_inc(*ppCounter, label_values) != 0) { tscError("monitorCounterInc failed to inc %" PRIx64 ":%s.", clusterId, counterName); goto end; } tscDebug("[monitor] monitorCounterInc %" PRIx64 "(%p):%s", pMonitor->clusterId, pMonitor, counterName); - end: +end: taosWUnLockLatch(&monitorLock); } @@ -495,7 +494,7 @@ static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offs } static void monitorSendSlowLogAtBeginning(int64_t clusterId, char** fileName, TdFilePtr pFile, int64_t offset) { - if (fileName == NULL){ + if (fileName == NULL) { return; } int64_t size = getFileSize(*fileName); @@ -504,10 +503,11 @@ static void monitorSendSlowLogAtBeginning(int64_t clusterId, char** fileName, Td tscDebug("[monitor] monitorSendSlowLogAtBeginning delete file:%s", *fileName); } else { int32_t code = monitorReadSend(clusterId, pFile, &offset, size, SLOW_LOG_READ_BEGINNIG, *fileName); - if (code == 0){ + if (code == 0) { tscDebug("[monitor] monitorSendSlowLogAtBeginning send slow log succ, clusterId:%" PRId64, clusterId); - }else{ - tscError("[monitor] monitorSendSlowLogAtBeginning send slow log failed, clusterId:%" PRId64 ",ret:%d", clusterId, code); + } else { + tscError("[monitor] monitorSendSlowLogAtBeginning send slow log failed, clusterId:%" PRId64 ",ret:%d", clusterId, + code); } *fileName = NULL; } diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index c9f166e565..9d5a8a111f 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -37,7 +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; +static int8_t pollFlag = 0; typedef struct { int32_t code; @@ -121,7 +121,7 @@ struct tmq_t { typedef struct SAskEpInfo { int32_t code; - tsem2_t sem; + tsem2_t sem; } SAskEpInfo; enum { @@ -191,7 +191,7 @@ typedef struct { } SMqPollRspWrapper; typedef struct { - tsem2_t rspSem; + tsem2_t rspSem; int32_t rspErr; } SMqSubscribeCbParam; @@ -219,12 +219,12 @@ typedef struct SMqVgCommon { } SMqVgCommon; typedef struct SMqSeekParam { - tsem2_t sem; + tsem2_t sem; int32_t code; } SMqSeekParam; typedef struct SMqCommittedParam { - tsem2_t sem; + tsem2_t sem; int32_t code; SMqVgOffset vgOffset; } SMqCommittedParam; @@ -242,18 +242,18 @@ typedef struct { int32_t waitingRspNum; int32_t code; tmq_commit_cb* callbackFn; - void* userParam; + void* userParam; } SMqCommitCbParamSet; typedef struct { SMqCommitCbParamSet* params; - char topicName[TSDB_TOPIC_FNAME_LEN]; - int32_t vgId; - int64_t consumerId; + char topicName[TSDB_TOPIC_FNAME_LEN]; + int32_t vgId; + int64_t consumerId; } SMqCommitCbParam; typedef struct SSyncCommitInfo { - tsem2_t sem; + tsem2_t sem; int32_t code; } SSyncCommitInfo; @@ -334,7 +334,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value if (strcasecmp(key, "session.timeout.ms") == 0) { int64_t tmp = taosStr2int64(value); - if (tmp < 6000 || tmp > 1800000){ + if (tmp < 6000 || tmp > 1800000) { return TMQ_CONF_INVALID; } conf->sessionTimeoutMs = tmp; @@ -343,7 +343,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value if (strcasecmp(key, "heartbeat.interval.ms") == 0) { int64_t tmp = taosStr2int64(value); - if (tmp < 1000 || tmp >= conf->sessionTimeoutMs){ + if (tmp < 1000 || tmp >= conf->sessionTimeoutMs) { return TMQ_CONF_INVALID; } conf->heartBeatIntervalMs = tmp; @@ -352,7 +352,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value if (strcasecmp(key, "max.poll.interval.ms") == 0) { int64_t tmp = taosStr2int64(value); - if (tmp < 1000 || tmp > INT32_MAX){ + if (tmp < 1000 || tmp > INT32_MAX) { return TMQ_CONF_INVALID; } conf->maxPollIntervalMs = tmp; @@ -515,7 +515,7 @@ static int32_t doSendCommitMsg(tmq_t* tmq, int32_t vgId, SEpSet* epSet, STqOffse SEncoder encoder = {0}; tEncoderInit(&encoder, abuf, len); - if(tEncodeMqVgOffset(&encoder, &pOffset) < 0) { + if (tEncodeMqVgOffset(&encoder, &pOffset) < 0) { tEncoderClear(&encoder); taosMemoryFree(buf); return TSDB_CODE_INVALID_PARA; @@ -552,9 +552,8 @@ static int32_t doSendCommitMsg(tmq_t* tmq, int32_t vgId, SEpSet* epSet, STqOffse pMsgSendInfo->fp = tmqCommitCb; pMsgSendInfo->msgType = TDMT_VND_TMQ_COMMIT_OFFSET; - int64_t transporterId = 0; (void)atomic_add_fetch_32(&pParamSet->waitingRspNum, 1); - code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, epSet, &transporterId, pMsgSendInfo); + code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, epSet, NULL, pMsgSendInfo); if (code != 0) { (void)atomic_sub_fetch_32(&pParamSet->waitingRspNum, 1); return code; @@ -562,7 +561,7 @@ static int32_t doSendCommitMsg(tmq_t* tmq, int32_t vgId, SEpSet* epSet, STqOffse return code; } -static int32_t getTopicByName(tmq_t* tmq, const char* pTopicName, SMqClientTopic **topic) { +static int32_t getTopicByName(tmq_t* tmq, const char* pTopicName, SMqClientTopic** topic) { int32_t numOfTopics = taosArrayGetSize(tmq->clientTopics); for (int32_t i = 0; i < numOfTopics; ++i) { SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i); @@ -577,8 +576,8 @@ static int32_t getTopicByName(tmq_t* tmq, const char* pTopicName, SMqClientTopic return TSDB_CODE_TMQ_INVALID_TOPIC; } -static int32_t prepareCommitCbParamSet(tmq_t* tmq, tmq_commit_cb* pCommitFp, void* userParam, - int32_t rspNum, SMqCommitCbParamSet** ppParamSet) { +static int32_t prepareCommitCbParamSet(tmq_t* tmq, tmq_commit_cb* pCommitFp, void* userParam, int32_t rspNum, + SMqCommitCbParamSet** ppParamSet) { SMqCommitCbParamSet* pParamSet = taosMemoryCalloc(1, sizeof(SMqCommitCbParamSet)); if (pParamSet == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -595,7 +594,7 @@ static int32_t prepareCommitCbParamSet(tmq_t* tmq, tmq_commit_cb* pCommitFp, voi static int32_t getClientVg(tmq_t* tmq, char* pTopicName, int32_t vgId, SMqClientVg** pVg) { SMqClientTopic* pTopic = NULL; - int32_t code = getTopicByName(tmq, pTopicName, &pTopic); + int32_t code = getTopicByName(tmq, pTopicName, &pTopic); if (code != 0) { tscError("consumer:0x%" PRIx64 " invalid topic name:%s", tmq->consumerId, pTopicName); return code; @@ -723,7 +722,7 @@ static void asyncCommitAllOffsets(tmq_t* tmq, tmq_commit_cb* pCommitFp, void* us taosRUnLockLatch(&tmq->lock); goto end; } - int32_t numOfVgroups = taosArrayGetSize(pTopic->vgs); + int32_t numOfVgroups = taosArrayGetSize(pTopic->vgs); tscDebug("consumer:0x%" PRIx64 " commit offset for topics:%s, numOfVgs:%d", tmq->consumerId, pTopic->topicName, numOfVgroups); for (int32_t j = 0; j < numOfVgroups; j++) { @@ -769,7 +768,7 @@ static void asyncCommitAllOffsets(tmq_t* tmq, tmq_commit_cb* pCommitFp, void* us if (pParamSet->waitingRspNum != 1) { // count down since waiting rsp num init as 1 code = commitRspCountDown(pParamSet, tmq->consumerId, "", 0); - if (code != 0){ + if (code != 0) { tscError("consumer:0x%" PRIx64 " commit rsp count down failed, code:%s", tmq->consumerId, tstrerror(code)); pParamSet = NULL; goto end; @@ -824,14 +823,14 @@ void tmqAssignDelayedCommitTask(void* param, void* tmrId) { } int32_t tmqHbCb(void* param, SDataBuf* pMsg, int32_t code) { - if (code != 0){ + if (code != 0) { goto _return; } if (pMsg == NULL || param == NULL) { code = TSDB_CODE_INVALID_PARA; goto _return; } - + SMqHbRsp rsp = {0}; code = tDeserializeSMqHbRsp(pMsg->pData, pMsg->len, &rsp); if (code != 0) { @@ -858,7 +857,7 @@ int32_t tmqHbCb(void* param, SDataBuf* pMsg, int32_t code) { taosWUnLockLatch(&tmq->lock); (void)taosReleaseRef(tmqMgmt.rsetId, refId); } - + tDestroySMqHbRsp(&rsp); _return: @@ -881,32 +880,32 @@ void tmqSendHbReq(void* param, void* tmrId) { req.epoch = tmq->epoch; req.pollFlag = atomic_load_8(&pollFlag); req.topics = taosArrayInit(taosArrayGetSize(tmq->clientTopics), sizeof(TopicOffsetRows)); - if (req.topics == NULL){ + if (req.topics == NULL) { return; } taosRLockLatch(&tmq->lock); for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) { - SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i); + SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i); if (pTopic == NULL) { continue; } int32_t numOfVgroups = taosArrayGetSize(pTopic->vgs); TopicOffsetRows* data = taosArrayReserve(req.topics, 1); - if (data == NULL){ + if (data == NULL) { continue; } (void)strcpy(data->topicName, pTopic->topicName); data->offsetRows = taosArrayInit(numOfVgroups, sizeof(OffsetRows)); - if (data->offsetRows == NULL){ + if (data->offsetRows == NULL) { continue; } for (int j = 0; j < numOfVgroups; j++) { SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j); - if (pVg == NULL){ + if (pVg == NULL) { continue; } - OffsetRows* offRows = taosArrayReserve(data->offsetRows, 1); - if (offRows == NULL){ + OffsetRows* offRows = taosArrayReserve(data->offsetRows, 1); + if (offRows == NULL) { continue; } offRows->vgId = pVg->vgId; @@ -955,8 +954,7 @@ void tmqSendHbReq(void* param, void* tmrId) { SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); - int64_t transporterId = 0; - int32_t code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); + int32_t code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, NULL, sendInfo); if (code != 0) { tscError("tmqSendHbReq asyncSendMsgToServer failed"); } @@ -964,7 +962,7 @@ void tmqSendHbReq(void* param, void* tmrId) { (void)atomic_val_compare_exchange_8(&pollFlag, 1, 0); OVER: tDestroySMqHbReq(&req); - if(tmrId != NULL){ + if (tmrId != NULL) { (void)taosTmrReset(tmqSendHbReq, tmq->heartBeatIntervalMs, param, tmqMgmt.timer, &tmq->hbLiveTimer); } (void)taosReleaseRef(tmqMgmt.rsetId, refId); @@ -1006,14 +1004,15 @@ void tmqHandleAllDelayedTask(tmq_t* pTmq) { continue; } tscDebug("consumer:0x%" PRIx64 " retrieve ep from mnode in 1s", pTmq->consumerId); - (void)taosTmrReset(tmqAssignAskEpTask, DEFAULT_ASKEP_INTERVAL, (void*)(pTmq->refId), tmqMgmt.timer, &pTmq->epTimer); + (void)taosTmrReset(tmqAssignAskEpTask, DEFAULT_ASKEP_INTERVAL, (void*)(pTmq->refId), tmqMgmt.timer, + &pTmq->epTimer); } else if (*pTaskType == TMQ_DELAYED_TASK__COMMIT) { tmq_commit_cb* pCallbackFn = pTmq->commitCb ? pTmq->commitCb : defaultCommitCbFn; asyncCommitAllOffsets(pTmq, pCallbackFn, pTmq->commitCbUserParam); tscDebug("consumer:0x%" PRIx64 " next commit to vnode(s) in %.2fs", pTmq->consumerId, pTmq->autoCommitInterval / 1000.0); (void)taosTmrReset(tmqAssignDelayedCommitTask, pTmq->autoCommitInterval, (void*)(pTmq->refId), tmqMgmt.timer, - &pTmq->commitTimer); + &pTmq->commitTimer); } else { tscError("consumer:0x%" PRIx64 " invalid task type:%d", pTmq->consumerId, *pTaskType); } @@ -1100,16 +1099,16 @@ int32_t tmq_subscription(tmq_t* tmq, tmq_list_t** topics) { taosRLockLatch(&tmq->lock); for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) { SMqClientTopic* topic = taosArrayGet(tmq->clientTopics, i); - if(topic == NULL) { + if (topic == NULL) { tscError("topic is null"); continue; } char* tmp = strchr(topic->topicName, '.'); - if(tmp == NULL) { + if (tmp == NULL) { tscError("topic name is invalid:%s", topic->topicName); continue; } - if(tmq_list_append(*topics, tmp+ 1) != 0) { + if (tmq_list_append(*topics, tmp + 1) != 0) { tscError("failed to append topic:%s", tmp + 1); continue; } @@ -1227,27 +1226,31 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { } code = taosOpenQueue(&pTmq->mqueue); if (code) { - tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, tstrerror(code), pTmq->groupId); + tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, tstrerror(code), + pTmq->groupId); SET_ERROR_MSG_TMQ("open queue failed") goto _failed; } code = taosOpenQueue(&pTmq->delayedTask); if (code) { - tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, tstrerror(code), pTmq->groupId); + tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, tstrerror(code), + pTmq->groupId); SET_ERROR_MSG_TMQ("open delayed task queue failed") goto _failed; } code = taosAllocateQall(&pTmq->qall); if (code) { - tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, tstrerror(code), pTmq->groupId); + tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, tstrerror(code), + pTmq->groupId); SET_ERROR_MSG_TMQ("allocate qall failed") goto _failed; } if (conf->groupId[0] == 0) { - tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, tstrerror(code), pTmq->groupId); + tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, tstrerror(code), + pTmq->groupId); SET_ERROR_MSG_TMQ("malloc tmq element failed or group is empty") goto _failed; } @@ -1287,8 +1290,8 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { // init semaphore if (tsem2_init(&pTmq->rspSem, 0, 0) != 0) { - tscError("consumer:0x %" PRIx64 " setup failed since %s, consumer group %s", pTmq->consumerId, tstrerror(TAOS_SYSTEM_ERROR(errno)), - pTmq->groupId); + tscError("consumer:0x %" PRIx64 " setup failed since %s, consumer group %s", pTmq->consumerId, + tstrerror(TAOS_SYSTEM_ERROR(errno)), pTmq->groupId); SET_ERROR_MSG_TMQ("init t_sem failed") goto _failed; } @@ -1371,7 +1374,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { SName name = {0}; code = tNameSetDbName(&name, tmq->pTscObj->acctId, topic, strlen(topic)); if (code) { - tscError("consumer:0x%" PRIx64 " cgroup:%s, failed to set topic name, code:%d", tmq->consumerId, tmq->groupId, code); + tscError("consumer:0x%" PRIx64 " cgroup:%s, failed to set topic name, code:%d", tmq->consumerId, tmq->groupId, + code); goto FAIL; } char* topicFName = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN); @@ -1382,7 +1386,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { code = tNameExtractFullName(&name, topicFName); if (code) { - tscError("consumer:0x%" PRIx64 " cgroup:%s, failed to extract topic name, code:%d", tmq->consumerId, tmq->groupId, code); + tscError("consumer:0x%" PRIx64 " cgroup:%s, failed to extract topic name, code:%d", tmq->consumerId, tmq->groupId, + code); taosMemoryFree(topicFName); goto FAIL; } @@ -1429,8 +1434,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); - int64_t transporterId = 0; - code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); + code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, NULL, sendInfo); if (code != 0) { goto FAIL; } @@ -1459,7 +1463,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { } tmq->epTimer = taosTmrStart(tmqAssignAskEpTask, DEFAULT_ASKEP_INTERVAL, (void*)(tmq->refId), tmqMgmt.timer); - tmq->commitTimer =taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, (void*)(tmq->refId), tmqMgmt.timer); + tmq->commitTimer = + taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, (void*)(tmq->refId), tmqMgmt.timer); if (tmq->epTimer == NULL || tmq->commitTimer == NULL) { code = TSDB_CODE_TSC_INTERNAL_ERROR; goto FAIL; @@ -1516,12 +1521,12 @@ static void setVgIdle(tmq_t* tmq, char* topicName, int32_t vgId) { } int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { - tmq_t* tmq = NULL; + tmq_t* tmq = NULL; SMqPollRspWrapper* pRspWrapper = NULL; - int8_t rspType = 0; - int32_t vgId = 0; - uint64_t requestId = 0; - SMqPollCbParam* pParam = (SMqPollCbParam*)param; + int8_t rspType = 0; + int32_t vgId = 0; + uint64_t requestId = 0; + SMqPollCbParam* pParam = (SMqPollCbParam*)param; if (pMsg == NULL) { return TSDB_CODE_TSC_INTERNAL_ERROR; } @@ -1530,7 +1535,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { taosMemoryFreeClear(pMsg->pEpSet); return TSDB_CODE_TSC_INTERNAL_ERROR; } - int64_t refId = pParam->refId; + int64_t refId = pParam->refId; vgId = pParam->vgId; requestId = pParam->requestId; tmq = taosAcquireRef(tmqMgmt.rsetId, refId); @@ -1621,18 +1626,19 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { } tDecoderClear(&decoder); (void)memcpy(&pRspWrapper->batchMetaRsp, pMsg->pData, sizeof(SMqRspHead)); - tscDebug("consumer:0x%" PRIx64 " recv poll batchmeta rsp, vgId:%d, reqId:0x%" PRIx64, tmq->consumerId, vgId,requestId); + tscDebug("consumer:0x%" PRIx64 " recv poll batchmeta rsp, vgId:%d, reqId:0x%" PRIx64, tmq->consumerId, vgId, + requestId); } else { // invalid rspType tscError("consumer:0x%" PRIx64 " invalid rsp msg received, type:%d ignored", tmq->consumerId, rspType); } END: - if (pRspWrapper){ + if (pRspWrapper) { pRspWrapper->code = code; pRspWrapper->vgId = vgId; (void)strcpy(pRspWrapper->topicName, pParam->topicName); code = taosWriteQitem(tmq->mqueue, pRspWrapper); - if(code != 0){ + if (code != 0) { tscError("consumer:0x%" PRIx64 " put poll res into mqueue failed, code:%d", tmq->consumerId, code); } } @@ -1676,7 +1682,7 @@ static void initClientTopicFromRsp(SMqClientTopic* pTopic, SMqSubTopicEp* pTopic } for (int32_t j = 0; j < vgNumGet; j++) { SMqSubVgEp* pVgEp = taosArrayGet(pTopicEp->vgs, j); - if (pVgEp == NULL){ + if (pVgEp == NULL) { continue; } (void)sprintf(vgKey, "%s:%d", pTopic->topicName, pVgEp->vgId); @@ -1712,7 +1718,7 @@ static void initClientTopicFromRsp(SMqClientTopic* pTopic, SMqSubTopicEp* pTopic clientVg.offsetInfo.committedOffset = offsetNew; clientVg.offsetInfo.beginOffset = offsetNew; } - if (taosArrayPush(pTopic->vgs, &clientVg) == NULL){ + if (taosArrayPush(pTopic->vgs, &clientVg) == NULL) { tscError("consumer:0x%" PRIx64 ", failed to push vg:%d into topic:%s", tmq->consumerId, pVgEp->vgId, pTopic->topicName); freeClientVg(&clientVg); @@ -1773,7 +1779,7 @@ static bool doUpdateLocalEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) .commitOffset = pVgCur->offsetInfo.committedOffset, .numOfRows = pVgCur->numOfRows, .vgStatus = pVgCur->vgStatus}; - if(taosHashPut(pVgOffsetHashMap, vgKey, strlen(vgKey), &info, sizeof(SVgroupSaveInfo)) != 0){ + if (taosHashPut(pVgOffsetHashMap, vgKey, strlen(vgKey), &info, sizeof(SVgroupSaveInfo)) != 0) { tscError("consumer:0x%" PRIx64 ", failed to put vg:%d into hashmap", tmq->consumerId, pVgCur->vgId); } } @@ -1787,7 +1793,7 @@ static bool doUpdateLocalEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) continue; } initClientTopicFromRsp(&topic, pTopicEp, pVgOffsetHashMap, tmq); - if(taosArrayPush(newTopics, &topic) == NULL){ + if (taosArrayPush(newTopics, &topic) == NULL) { tscError("consumer:0x%" PRIx64 ", failed to push topic:%s into new topics", tmq->consumerId, topic.topicName); freeClientTopic(&topic); } @@ -1919,7 +1925,7 @@ static void tmqBuildRspFromWrapperInner(SMqPollRspWrapper* pWrapper, SMqClientVg if (!pDataRsp->withSchema) { // withSchema is false if subscribe subquery, true if subscribe db or stable pDataRsp->withSchema = true; pDataRsp->blockSchema = taosArrayInit(pDataRsp->blockNum, sizeof(void*)); - if (pDataRsp->blockSchema == NULL){ + if (pDataRsp->blockSchema == NULL) { tscError("failed to allocate memory for blockSchema"); return; } @@ -1938,7 +1944,7 @@ static void tmqBuildRspFromWrapperInner(SMqPollRspWrapper* pWrapper, SMqClientVg if (needTransformSchema) { // withSchema is false if subscribe subquery, true if subscribe db or stable SSchemaWrapper* schema = tCloneSSchemaWrapper(&pWrapper->topicHandle->schema); if (schema) { - if (taosArrayPush(pDataRsp->blockSchema, &schema) == NULL){ + if (taosArrayPush(pDataRsp->blockSchema, &schema) == NULL) { tscError("failed to push schema into blockSchema"); continue; } @@ -1947,7 +1953,8 @@ static void tmqBuildRspFromWrapperInner(SMqPollRspWrapper* pWrapper, SMqClientVg } } -int32_t tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pVg, int64_t* numOfRows, SMqRspObj** ppRspObj) { +int32_t tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pVg, int64_t* numOfRows, + SMqRspObj** ppRspObj) { SMqRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqRspObj)); if (pRspObj == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -1959,7 +1966,8 @@ int32_t tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pVg, in return 0; } -int32_t tmqBuildTaosxRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pVg, int64_t* numOfRows, SMqTaosxRspObj** ppRspObj) { +int32_t tmqBuildTaosxRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pVg, int64_t* numOfRows, + SMqTaosxRspObj** ppRspObj) { SMqTaosxRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqTaosxRspObj)); if (pRspObj == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -2026,10 +2034,9 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p sendInfo->fp = tmqPollCb; sendInfo->msgType = TDMT_VND_TMQ_CONSUME; - int64_t transporterId = 0; - char offsetFormatBuf[TSDB_OFFSET_LEN] = {0}; + char offsetFormatBuf[TSDB_OFFSET_LEN] = {0}; tFormatOffset(offsetFormatBuf, tListLen(offsetFormatBuf), &pVg->offsetInfo.endOffset); - code = asyncSendMsgToServer(pTmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo); + code = asyncSendMsgToServer(pTmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, NULL, sendInfo); tscDebug("consumer:0x%" PRIx64 " send poll to %s vgId:%d, code:%d, epoch %d, req:%s, reqId:0x%" PRIx64, pTmq->consumerId, pTopic->topicName, pVg->vgId, code, pTmq->epoch, offsetFormatBuf, req.reqId); if (code != 0) { @@ -2056,10 +2063,10 @@ static int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) { for (int i = 0; i < numOfTopics; i++) { SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i); - if (pTopic == NULL){ + if (pTopic == NULL) { continue; } - int32_t numOfVg = taosArrayGetSize(pTopic->vgs); + int32_t numOfVg = taosArrayGetSize(pTopic->vgs); if (pTopic->noPrivilege) { tscDebug("consumer:0x%" PRIx64 " has no privilegr for topic:%s", tmq->consumerId, pTopic->topicName); continue; @@ -2069,7 +2076,7 @@ static int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) { if (pVg == NULL) { continue; } - int64_t elapsed = taosGetTimestampMs() - pVg->emptyBlockReceiveTs; + int64_t elapsed = taosGetTimestampMs() - pVg->emptyBlockReceiveTs; if (elapsed < EMPTY_BLOCK_POLL_IDLE_DURATION && elapsed >= 0) { // less than 10ms tscDebug("consumer:0x%" PRIx64 " epoch %d, vgId:%d idle for 10ms before start next poll", tmq->consumerId, tmq->epoch, pVg->vgId); @@ -2220,8 +2227,8 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout) { pVg->blockSleepForReplay = pRsp->rsp.sleepTime; if (pVg->blockSleepForReplay > 0) { if (taosTmrStart(tmqReplayTask, pVg->blockSleepForReplay, (void*)(tmq->refId), tmqMgmt.timer) == NULL) { - tscError("consumer:0x%" PRIx64 " failed to start replay timer, vgId:%d, sleep:%"PRId64, tmq->consumerId, - pVg->vgId, pVg->blockSleepForReplay); + tscError("consumer:0x%" PRIx64 " failed to start replay timer, vgId:%d, sleep:%" PRId64, + tmq->consumerId, pVg->vgId, pVg->blockSleepForReplay); } } } @@ -2302,7 +2309,7 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout) { pollRspWrapper->batchMetaRsp.head.walsver, pollRspWrapper->batchMetaRsp.head.walever, tmq->consumerId, true); SMqBatchMetaRspObj* pRsp = NULL; - (void)tmqBuildBatchMetaRspFromWrapper(pollRspWrapper, &pRsp) ; + (void)tmqBuildBatchMetaRspFromWrapper(pollRspWrapper, &pRsp); taosFreeQitem(pRspWrapper); taosWUnLockLatch(&tmq->lock); return pRsp; @@ -2349,9 +2356,9 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout) { } // build rsp - int64_t numOfRows = 0; - SMqTaosxRspObj* pRsp = NULL; - if (tmqBuildTaosxRspFromWrapper(pollRspWrapper, pVg, &numOfRows, &pRsp) !=0 ) { + int64_t numOfRows = 0; + SMqTaosxRspObj* pRsp = NULL; + if (tmqBuildTaosxRspFromWrapper(pollRspWrapper, pVg, &numOfRows, &pRsp) != 0) { tscError("consumer:0x%" PRIx64 " build taosx rsp failed, vgId:%d", tmq->consumerId, pVg->vgId); } tmq->totalRows += numOfRows; @@ -2471,7 +2478,7 @@ static void displayConsumeStatistics(tmq_t* pTmq) { tscDebug("consumer:0x%" PRIx64 " rows dist end", pTmq->consumerId); } -static int32_t innerClose(tmq_t* tmq){ +static int32_t innerClose(tmq_t* tmq) { if (tmq->status != TMQ_CONSUMER_STATUS__READY) { tscInfo("consumer:0x%" PRIx64 " not in ready state, unsubscribe it directly", tmq->consumerId); return 0; @@ -2485,7 +2492,7 @@ static int32_t innerClose(tmq_t* tmq){ tmqSendHbReq((void*)(tmq->refId), NULL); tmq_list_t* lst = tmq_list_new(); - if (lst == NULL){ + if (lst == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } int32_t code = tmq_subscribe(tmq, lst); @@ -2499,7 +2506,7 @@ int32_t tmq_unsubscribe(tmq_t* tmq) { int32_t code = 0; if (atomic_load_8(&tmq->status) != TMQ_CONSUMER_STATUS__CLOSED) { code = innerClose(tmq); - if(code == 0){ + if (code == 0) { atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__CLOSED); } } @@ -2514,12 +2521,12 @@ int32_t tmq_consumer_close(tmq_t* tmq) { int32_t code = 0; if (atomic_load_8(&tmq->status) != TMQ_CONSUMER_STATUS__CLOSED) { code = innerClose(tmq); - if(code == 0){ + if (code == 0) { atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__CLOSED); } } - if (code == 0){ + if (code == 0) { (void)taosRemoveRef(tmqMgmt.rsetId, tmq->refId); } return code; @@ -2562,13 +2569,13 @@ const char* tmq_get_topic_name(TAOS_RES* res) { return NULL; } if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) { - char *tmp = strchr(((SMqRspObjCommon*)res)->topic, '.'); + char* tmp = strchr(((SMqRspObjCommon*)res)->topic, '.'); if (tmp == NULL) { return NULL; } return tmp + 1; } else if (TD_RES_TMQ_META(res)) { - char *tmp = strchr(((SMqMetaRspObj*)res)->topic, '.'); + char* tmp = strchr(((SMqMetaRspObj*)res)->topic, '.'); if (tmp == NULL) { return NULL; } @@ -2584,13 +2591,13 @@ const char* tmq_get_db_name(TAOS_RES* res) { } if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res) || TD_RES_TMQ_BATCH_META(res)) { - char *tmp = strchr(((SMqRspObjCommon*)res)->db, '.'); + char* tmp = strchr(((SMqRspObjCommon*)res)->db, '.'); if (tmp == NULL) { return NULL; } return tmp + 1; } else if (TD_RES_TMQ_META(res)) { - char *tmp = strchr(((SMqMetaRspObj*)res)->db, '.'); + char* tmp = strchr(((SMqMetaRspObj*)res)->db, '.'); if (tmp == NULL) { return NULL; } @@ -2690,7 +2697,7 @@ int32_t tmq_commit_sync(tmq_t* tmq, const TAOS_RES* pRes) { int32_t code = 0; SSyncCommitInfo* pInfo = taosMemoryMalloc(sizeof(SSyncCommitInfo)); - if(pInfo == NULL) { + if (pInfo == NULL) { tscError("failed to allocate memory for sync commit"); return TSDB_CODE_OUT_OF_MEMORY; } @@ -2836,7 +2843,7 @@ int32_t askEpCb(void* param, SDataBuf* pMsg, int32_t code) { if (param == NULL) { goto FAIL; } - + SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param; tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, pParam->refId); if (tmq == NULL) { @@ -2857,7 +2864,7 @@ int32_t askEpCb(void* param, SDataBuf* pMsg, int32_t code) { tscDebug("consumer:0x%" PRIx64 ", recv ep, msg epoch %d, current epoch %d", tmq->consumerId, head->epoch, epoch); if (pParam->sync) { SMqAskEpRsp rsp = {0}; - if(tDecodeSMqAskEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &rsp) != NULL){ + if (tDecodeSMqAskEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &rsp) != NULL) { (void)doUpdateLocalEp(tmq, head->epoch, &rsp); } tDeleteSMqAskEpRsp(&rsp); @@ -2871,10 +2878,10 @@ int32_t askEpCb(void* param, SDataBuf* pMsg, int32_t code) { pWrapper->tmqRspType = TMQ_MSG_TYPE__EP_RSP; pWrapper->epoch = head->epoch; (void)memcpy(&pWrapper->msg, pMsg->pData, sizeof(SMqRspHead)); - if (tDecodeSMqAskEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pWrapper->msg) == NULL){ + if (tDecodeSMqAskEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pWrapper->msg) == NULL) { tmqFreeRspWrapper((SMqRspWrapper*)pWrapper); taosFreeQitem(pWrapper); - }else{ + } else { (void)taosWriteQitem(tmq->mqueue, pWrapper); } } @@ -3015,7 +3022,7 @@ int32_t tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4, SReqResultInfo** pRes if (common->withSchema) { doFreeReqResultInfo(&pRspObj->resInfo); SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(common->blockSchema, pRspObj->resIter); - if (pSW){ + if (pSW) { TAOS_CHECK_RETURN(setResSchemaInfo(&pRspObj->resInfo, pSW->pSchema, pSW->nCols)); } } @@ -3032,9 +3039,9 @@ int32_t tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4, SReqResultInfo** pRes pRspObj->resInfo.precision = precision; pRspObj->resInfo.totalRows += pRspObj->resInfo.numOfRows; - int32_t code = setResultDataPtr(&pRspObj->resInfo, pRspObj->resInfo.fields, pRspObj->resInfo.numOfCols, pRspObj->resInfo.numOfRows, - convertUcs4); - if (code != 0){ + int32_t code = setResultDataPtr(&pRspObj->resInfo, pRspObj->resInfo.fields, pRspObj->resInfo.numOfCols, + pRspObj->resInfo.numOfRows, convertUcs4); + if (code != 0) { return code; } *pResInfo = &pRspObj->resInfo; @@ -3062,18 +3069,18 @@ static int32_t tmqGetWalInfoCb(void* param, SDataBuf* pMsg, int32_t code) { tDecoderInit(&decoder, POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), pMsg->len - sizeof(SMqRspHead)); code = tDecodeMqDataRsp(&decoder, &rsp); tDecoderClear(&decoder); - if (code != 0){ + if (code != 0) { goto END; } - SMqRspHead* pHead = pMsg->pData; + SMqRspHead* pHead = pMsg->pData; tmq_topic_assignment assignment = {.begin = pHead->walsver, .end = pHead->walever + 1, .currentOffset = rsp.common.rspOffset.version, .vgId = pParam->vgId}; (void)taosThreadMutexLock(&pCommon->mutex); - if(taosArrayPush(pCommon->pList, &assignment) == NULL){ + if (taosArrayPush(pCommon->pList, &assignment) == NULL) { tscError("consumer:0x%" PRIx64 " failed to push the wal info from vgId:%d for topic:%s", pCommon->consumerId, pParam->vgId, pCommon->pTopicName); code = TSDB_CODE_TSC_INTERNAL_ERROR; @@ -3184,7 +3191,7 @@ int64_t getCommittedFromServer(tmq_t* tmq, char* tname, int32_t vgId, SEpSet* ep taosMemoryFree(sendInfo); return TSDB_CODE_OUT_OF_MEMORY; } - if (tsem2_init(&pParam->sem, 0, 0) != 0){ + if (tsem2_init(&pParam->sem, 0, 0) != 0) { taosMemoryFree(buf); taosMemoryFree(sendInfo); taosMemoryFree(pParam); @@ -3198,8 +3205,7 @@ int64_t getCommittedFromServer(tmq_t* tmq, char* tname, int32_t vgId, SEpSet* ep sendInfo->fp = tmCommittedCb; sendInfo->msgType = TDMT_VND_TMQ_VG_COMMITTEDINFO; - int64_t transporterId = 0; - code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, epSet, &transporterId, sendInfo); + code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, epSet, NULL, sendInfo); if (code != 0) { (void)tsem2_destroy(&pParam->sem); taosMemoryFree(pParam); @@ -3348,7 +3354,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a taosWLockLatch(&tmq->lock); SMqClientTopic* pTopic = NULL; - int32_t code = getTopicByName(tmq, tname, &pTopic); + int32_t code = getTopicByName(tmq, tname, &pTopic); if (code != 0) { tscError("consumer:0x%" PRIx64 " invalid topic name:%s", tmq->consumerId, pTopicName); goto end; @@ -3358,10 +3364,10 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a *numOfAssignment = taosArrayGetSize(pTopic->vgs); for (int32_t j = 0; j < (*numOfAssignment); ++j) { SMqClientVg* pClientVg = taosArrayGet(pTopic->vgs, j); - if (pClientVg == NULL){ + if (pClientVg == NULL) { continue; } - int32_t type = pClientVg->offsetInfo.beginOffset.type; + int32_t type = pClientVg->offsetInfo.beginOffset.type; if (isInSnapshotMode(type, tmq->useSnapshot)) { tscError("consumer:0x%" PRIx64 " offset type:%d not wal version, assignment not allowed", tmq->consumerId, type); code = TSDB_CODE_TMQ_SNAPSHOT_ERROR; @@ -3381,7 +3387,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a for (int32_t j = 0; j < (*numOfAssignment); ++j) { SMqClientVg* pClientVg = taosArrayGet(pTopic->vgs, j); - if (pClientVg == NULL){ + if (pClientVg == NULL) { continue; } if (pClientVg->offsetInfo.beginOffset.type != TMQ_OFFSET__LOG) { @@ -3410,7 +3416,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a code = TSDB_CODE_OUT_OF_MEMORY; goto end; } - if (tsem2_init(&pCommon->rsp, 0, 0) != 0){ + if (tsem2_init(&pCommon->rsp, 0, 0) != 0) { code = TSDB_CODE_OUT_OF_MEMORY; goto end; } @@ -3420,7 +3426,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a for (int32_t i = 0; i < (*numOfAssignment); ++i) { SMqClientVg* pClientVg = taosArrayGet(pTopic->vgs, i); - if (pClientVg == NULL){ + if (pClientVg == NULL) { continue; } SMqVgWalInfoParam* pParam = taosMemoryMalloc(sizeof(SMqVgWalInfoParam)); @@ -3475,13 +3481,12 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a sendInfo->fp = tmqGetWalInfoCb; sendInfo->msgType = TDMT_VND_TMQ_VG_WALINFO; - int64_t transporterId = 0; - char offsetFormatBuf[TSDB_OFFSET_LEN] = {0}; + char offsetFormatBuf[TSDB_OFFSET_LEN] = {0}; tFormatOffset(offsetFormatBuf, tListLen(offsetFormatBuf), &pClientVg->offsetInfo.beginOffset); tscInfo("consumer:0x%" PRIx64 " %s retrieve wal info vgId:%d, epoch %d, req:%s, reqId:0x%" PRIx64, tmq->consumerId, pTopic->topicName, pClientVg->vgId, tmq->epoch, offsetFormatBuf, req.reqId); - code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pClientVg->epSet, &transporterId, sendInfo); + code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pClientVg->epSet, NULL, sendInfo); if (code != 0) { goto end; } @@ -3504,7 +3509,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a for (int32_t i = 0; i < taosArrayGetSize(pTopic->vgs); ++i) { SMqClientVg* pClientVg = taosArrayGet(pTopic->vgs, i); - if (pClientVg == NULL){ + if (pClientVg == NULL) { continue; } if (pClientVg->vgId != p->vgId) { @@ -3631,7 +3636,7 @@ int32_t tmq_offset_seek(tmq_t* tmq, const char* pTopicName, int32_t vgId, int64_ taosMemoryFree(sendInfo); return TSDB_CODE_OUT_OF_MEMORY; } - if (tsem2_init(&pParam->sem, 0, 0) != 0){ + if (tsem2_init(&pParam->sem, 0, 0) != 0) { taosMemoryFree(msg); taosMemoryFree(sendInfo); taosMemoryFree(pParam); @@ -3645,8 +3650,7 @@ int32_t tmq_offset_seek(tmq_t* tmq, const char* pTopicName, int32_t vgId, int64_ sendInfo->fp = tmqSeekCb; sendInfo->msgType = TDMT_VND_TMQ_SEEK; - int64_t transporterId = 0; - code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); + code = asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, NULL, sendInfo); if (code != 0) { (void)tsem2_destroy(&pParam->sem); taosMemoryFree(pParam); diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index a312dce164..11ad36dec6 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -56,13 +56,13 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu } for (int32_t i = 0; i < taskNum; ++i) { - int32_t* taskId = taosArrayGet(cbParam->taskId, i); + int32_t* taskId = taosArrayGet(cbParam->taskId, i); if (NULL == taskId) { ctgError("taosArrayGet %d taskId failed, total:%d", i, (int32_t)taosArrayGetSize(cbParam->taskId)); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } - int32_t* msgIdx = taosArrayGet(cbParam->msgIdx, i); + int32_t* msgIdx = taosArrayGet(cbParam->msgIdx, i); if (NULL == msgIdx) { ctgError("taosArrayGet %d msgIdx failed, total:%d", i, (int32_t)taosArrayGetSize(cbParam->msgIdx)); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); @@ -114,7 +114,8 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu ctgDebug("QID:0x%" PRIx64 " ctg task %d idx %d start to handle rsp %s, pBatchs: %p", pJob->queryId, pTask->taskId, pRsp->msgIdx, TMSG_INFO(taskMsg.msgType + 1), pBatchs); - (void)(*gCtgAsyncFps[pTask->type].handleRspFp)(&tReq, pRsp->reqType, &taskMsg, (pRsp->rspCode ? pRsp->rspCode : rspCode)); // error handled internal + (void)(*gCtgAsyncFps[pTask->type].handleRspFp)( + &tReq, pRsp->reqType, &taskMsg, (pRsp->rspCode ? pRsp->rspCode : rspCode)); // error handled internal } CTG_ERR_JRET(ctgLaunchBatchs(pJob->pCtg, pJob, pBatchs)); @@ -417,12 +418,12 @@ int32_t ctgHandleMsgCallback(void* param, SDataBuf* pMsg, int32_t rspCode) { if (TDMT_VND_BATCH_META == cbParam->reqType || TDMT_MND_BATCH_META == cbParam->reqType) { CTG_ERR_JRET(ctgHandleBatchRsp(pJob, cbParam, pMsg, rspCode)); } else { - int32_t* taskId = taosArrayGet(cbParam->taskId, 0); + int32_t* taskId = taosArrayGet(cbParam->taskId, 0); if (NULL == taskId) { ctgError("taosArrayGet %d taskId failed, total:%d", 0, (int32_t)taosArrayGetSize(cbParam->taskId)); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } - + SCtgTask* pTask = taosArrayGet(pJob->pTasks, *taskId); if (NULL == pTask) { ctgError("taosArrayGet %d SCtgTask failed, total:%d", *taskId, (int32_t)taosArrayGetSize(pJob->pTasks)); @@ -445,7 +446,7 @@ int32_t ctgHandleMsgCallback(void* param, SDataBuf* pMsg, int32_t rspCode) { ctgError("get task %d SCtgMsgCtx failed, taskType:%d", -1, pTask->type); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } - + pMsgCtx->pBatchs = pBatchs; #endif @@ -526,8 +527,7 @@ int32_t ctgAsyncSendMsg(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob* pJob, pMsgSendInfo->msgInfo.handle = NULL; pMsgSendInfo->msgType = msgType; - int64_t transporterId = 0; - code = asyncSendMsgToServer(pConn->pTrans, &pConn->mgmtEps, &transporterId, pMsgSendInfo); + code = asyncSendMsgToServer(pConn->pTrans, &pConn->mgmtEps, NULL, pMsgSendInfo); pMsgSendInfo = NULL; if (code) { ctgError("asyncSendMsgToSever failed, error: %s", tstrerror(code)); @@ -558,9 +558,9 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT ctgError("get task %d SCtgMsgCtx failed, taskType:%d", tReq->msgIdx, pTask->type); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } - - SHashObj* pBatchs = pMsgCtx->pBatchs; - SCtgBatch* pBatch = taosHashGet(pBatchs, &vgId, sizeof(vgId)); + + SHashObj* pBatchs = pMsgCtx->pBatchs; + SCtgBatch* pBatch = taosHashGet(pBatchs, &vgId, sizeof(vgId)); if (NULL == pBatch) { newBatch.pMsgs = taosArrayInit(pJob->subTaskNum, sizeof(SBatchMsg)); newBatch.pTaskIds = taosArrayInit(pJob->subTaskNum, sizeof(int32_t)); @@ -599,7 +599,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx; SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx); CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName)); - } else if (CTG_TASK_GET_TB_TSMA == pTask->type){ + } else if (CTG_TASK_GET_TB_TSMA == pTask->type) { SCtgTbTSMACtx* pCtx = pTask->taskCtx; SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx); STablesReq* pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx); @@ -616,10 +616,11 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT SCtgTbTSMACtx* pCtx = pTask->taskCtx; SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx); if (NULL == pFetch) { - ctgError("fail to get %d SCtgTSMAFetch, totalFetchs:%d", tReq->msgIdx, (int32_t)taosArrayGetSize(pCtx->pFetches)); + ctgError("fail to get %d SCtgTSMAFetch, totalFetchs:%d", tReq->msgIdx, + (int32_t)taosArrayGetSize(pCtx->pFetches)); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } - STablesReq* pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx); + STablesReq* pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx); if (NULL == pTbReq) { ctgError("fail to get %d STablesReq, totalTables:%d", pFetch->dbIdx, (int32_t)taosArrayGetSize(pCtx->pNames)); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); @@ -675,7 +676,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx; SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx); CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName)); - } else if (CTG_TASK_GET_TB_TSMA == pTask->type){ + } else if (CTG_TASK_GET_TB_TSMA == pTask->type) { SCtgTbTSMACtx* pCtx = pTask->taskCtx; SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx); STablesReq* pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx); @@ -689,22 +690,23 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT pName = ctx->pName; } } else if (TDMT_VND_GET_STREAM_PROGRESS == msgType) { - SCtgTbTSMACtx* pCtx = pTask->taskCtx; - SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx); - if (NULL == pFetch) { - ctgError("fail to get %d SCtgTSMAFetch, totalFetchs:%d", tReq->msgIdx, (int32_t)taosArrayGetSize(pCtx->pFetches)); - CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); - } - STablesReq* pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx); - if (NULL == pTbReq) { - ctgError("fail to get %d STablesReq, totalTables:%d", pFetch->dbIdx, (int32_t)taosArrayGetSize(pCtx->pNames)); - CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); - } - pName = taosArrayGet(pTbReq->pTables, pFetch->tbIdx); - if (NULL == pName) { - ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables)); - CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); - } + SCtgTbTSMACtx* pCtx = pTask->taskCtx; + SCtgTSMAFetch* pFetch = taosArrayGet(pCtx->pFetches, tReq->msgIdx); + if (NULL == pFetch) { + ctgError("fail to get %d SCtgTSMAFetch, totalFetchs:%d", tReq->msgIdx, + (int32_t)taosArrayGetSize(pCtx->pFetches)); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + STablesReq* pTbReq = taosArrayGet(pCtx->pNames, pFetch->dbIdx); + if (NULL == pTbReq) { + ctgError("fail to get %d STablesReq, totalTables:%d", pFetch->dbIdx, (int32_t)taosArrayGetSize(pCtx->pNames)); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + pName = taosArrayGet(pTbReq->pTables, pFetch->tbIdx); + if (NULL == pName) { + ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables)); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + } } else { ctgError("invalid vnode msgType %d", msgType); CTG_ERR_JRET(TSDB_CODE_APP_ERROR); @@ -1629,9 +1631,9 @@ int32_t ctgGetViewInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* } int32_t ctgGetTbTSMAFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* name, STableTSMAInfoRsp* out, - SCtgTaskReq* tReq, int32_t reqType) { - char* msg = NULL; - int32_t msgLen = 0; + SCtgTaskReq* tReq, int32_t reqType) { + char* msg = NULL; + int32_t msgLen = 0; SCtgTask* pTask = tReq ? tReq->pTask : NULL; void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont; char tbFName[TSDB_TABLE_FNAME_LEN]; @@ -1720,7 +1722,7 @@ int32_t ctgGetStreamProgressFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, c #if CTG_BATCH_FETCH CTG_RET(ctgAddBatch(pCtg, vgroupInfo->vgId, &vConn, tReq, reqType, msg, msgLen)); #else - char dbFName[TSDB_DB_FNAME_LEN]; + char dbFName[TSDB_DB_FNAME_LEN]; (void)tNameGetFullDbName(pTbName, dbFName); SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { @@ -1731,7 +1733,8 @@ int32_t ctgGetStreamProgressFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, c CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, vgroupInfo->vgId, reqType, msg, msgLen)); + CTG_RET( + ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, vgroupInfo->vgId, reqType, msg, msgLen)); #endif } diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c index 6f226ecb21..9555fef2ee 100644 --- a/source/libs/executor/src/dataInserter.c +++ b/source/libs/executor/src/dataInserter.c @@ -61,14 +61,14 @@ int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) { if (code) { pInserter->submitRes.code = code; } - + if (code == TSDB_CODE_SUCCESS) { pInserter->submitRes.pRsp = taosMemoryCalloc(1, sizeof(SSubmitRsp2)); if (NULL == pInserter->submitRes.pRsp) { pInserter->submitRes.code = terrno; goto _return; } - + SDecoder coder = {0}; tDecoderInit(&coder, pMsg->pData, pMsg->len); code = tDecodeSSubmitRsp2(&coder, pInserter->submitRes.pRsp); @@ -108,7 +108,7 @@ _return: (void)tsem_post(&pInserter->ready); taosMemoryFree(pMsg->pData); - + return TSDB_CODE_SUCCESS; } @@ -136,8 +136,7 @@ static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, void* pMsg, int pMsgSendInfo->msgType = TDMT_VND_SUBMIT; pMsgSendInfo->fp = inserterCallback; - int64_t transporterId = 0; - return asyncSendMsgToServer(pTransporter, pEpset, &transporterId, pMsgSendInfo); + return asyncSendMsgToServer(pTransporter, pEpset, NULL, pMsgSendInfo); } static int32_t submitReqToMsg(int32_t vgId, SSubmitReq2* pReq, void** pData, int32_t* pLen) { @@ -166,7 +165,7 @@ static int32_t submitReqToMsg(int32_t vgId, SSubmitReq2* pReq, void** pData, int } else { taosMemoryFree(pBuf); } - + return code; } @@ -228,7 +227,7 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; goto _end; } - void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); + void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); switch (pColInfoData->info.type) { case TSDB_DATA_TYPE_NCHAR: @@ -327,11 +326,11 @@ _end: tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE); taosMemoryFree(pReq); } - + return terrno; } *ppReq = pReq; - + return TSDB_CODE_SUCCESS; } @@ -458,7 +457,8 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat inserter->explain = pInserterNode->explain; int64_t suid = 0; - int32_t code = pManager->pAPI->metaFn.getTableSchema(inserter->pParam->readHandle->vnode, pInserterNode->tableId, &inserter->pSchema, &suid); + int32_t code = pManager->pAPI->metaFn.getTableSchema(inserter->pParam->readHandle->vnode, pInserterNode->tableId, + &inserter->pSchema, &suid); if (code) { terrno = code; goto _return; @@ -480,9 +480,9 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat inserter->pCols = taosHashInit(pInserterNode->pCols->length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT), false, HASH_NO_LOCK); if (NULL == inserter->pCols) { - goto _return; + goto _return; } - + SNode* pNode = NULL; int32_t i = 0; FOREACH(pNode, pInserterNode->pCols) { diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index d8a2331980..7b55aff5ca 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -2118,8 +2118,7 @@ static SSDataBlock* sysTableScanFromMNode(SOperatorInfo* pOperator, SSysTableSca pMsgSendInfo->fp = loadSysTableCallback; pMsgSendInfo->requestId = pTaskInfo->id.queryId; - int64_t transporterId = 0; - code = asyncSendMsgToServer(pInfo->readHandle.pMsgCb->clientRpc, &pInfo->epSet, &transporterId, pMsgSendInfo); + code = asyncSendMsgToServer(pInfo->readHandle.pMsgCb->clientRpc, &pInfo->epSet, NULL, pMsgSendInfo); if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); pTaskInfo->code = code; diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 14118f189b..15f2a7b500 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -997,8 +997,7 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, SSchTrans *trans, SQuery pTask->lastMsgType = msgType; } - int64_t transporterId = 0; - code = asyncSendMsgToServerExt(trans->pTrans, epSet, &transporterId, pMsgSendInfo, persistHandle, ctx); + code = asyncSendMsgToServerExt(trans->pTrans, epSet, NULL, pMsgSendInfo, persistHandle, ctx); pMsgSendInfo = NULL; if (code) { SCH_ERR_JRET(code); diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index df7b4f8fcf..078ede9d73 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -114,6 +114,7 @@ typedef struct SExHandle { void* handle; int64_t refId; void* pThrd; + int8_t pThrdIdx; queue q; int8_t inited; SRWLatch latch; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c3808fba58..90b47e1ef8 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -96,9 +96,16 @@ typedef struct SCliConn { int32_t seq; int32_t shareCnt; - int8_t registered; + int8_t registered; + int8_t connnected; + SHashObj* pQTable; } SCliConn; +typedef struct { + SCliConn* conn; + void* arg; +} SReqState; + typedef struct SCliReq { SReqCtx* ctx; STransMsg msg; @@ -146,6 +153,8 @@ typedef struct SCliThrd { int32_t (*initCb)(void* arg, SCliReq* pReq, STransMsg* pResp); int32_t (*notifyCb)(void* arg, SCliReq* pReq, STransMsg* pResp); int32_t (*notifyExceptCb)(void* arg, SCliReq* pReq, STransMsg* pResp); + + SHashObj* pIdConnTable; } SCliThrd; typedef struct SCliObj { @@ -229,7 +238,6 @@ 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 -static void cliHandleResp(SCliConn* conn); // handle except about conn static void cliHandleExcept(SCliConn* conn, int32_t code); static void cliReleaseUnfinishedMsg(SCliConn* conn); @@ -257,6 +265,9 @@ static FORCE_INLINE void destroyReqAndAhanlde(void* cmsg); static FORCE_INLINE int cliRBChoseIdx(STrans* pInst); static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx); +int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn); +int32_t cliMayGetHandleState(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); + static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); @@ -479,7 +490,7 @@ int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { int8_t cliMayRecycleConn(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; - if (transQueueSize(&conn->reqs) == 0) { + if (transQueueSize(&conn->reqs) == 0 && taosHashGetSize(conn->pQTable) == 0) { (void)delConnFromHeapCache(pThrd->connHeapCache, conn); addConnToPool(pThrd->pool, conn); return 1; @@ -499,12 +510,41 @@ int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHe pResp->info.seqNum = htonl(pHead->seqNum); return 0; } +int32_t cliConnMayHandleReleasReq(SCliConn* conn, STransMsgHead* pHead) { + int32_t code = 0; + SCliThrd* pThrd = conn->hostThrd; + if (pHead->msgType == TDMT_SCH_TASK_RELEASE) { + int64_t qId = taosHton64(pHead->qid); + code = taosHashRemove(conn->pQTable, &qId, sizeof(qId)); + if (code != 0) { + tDebug("%s conn %p failed to release req %ld from conn", CONN_GET_INST_LABEL(conn), conn, qId); + } + + code = taosHashRemove(pThrd->pIdConnTable, &qId, sizeof(qId)); + if (code != 0) { + tDebug("%s conn %p failed to release req %ld from thrd ", CONN_GET_INST_LABEL(conn), conn, qId); + } + tDebug("%s conn %p release req %ld", CONN_GET_INST_LABEL(conn), conn, qId); + + for (int32_t i = 0; i < transQueueSize(&conn->reqs); i++) { + SCliReq* pReqs = transQueueGet(&conn->reqs, i); + if (pReqs->msg.info.qId == qId) { + transQueueRm(&conn->reqs, i); + destroyReq(pReqs); + i--; + } + } + return 1; + } + return 0; +} void cliHandleResp2(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; cliResetConnTimer(conn); + SCliReq* pReq = NULL; STransMsgHead* pHead = NULL; int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 0); @@ -522,39 +562,39 @@ void cliHandleResp2(SCliConn* conn) { return; } + if (cliConnMayHandleReleasReq(conn, pHead)) { + if (cliMayRecycleConn(conn)) { + return; + } + + return; + } + int64_t qId = taosHton64(pHead->qid); + pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); - SCliReq* pReq = NULL; - int32_t seq = htonl(pHead->seqNum); + int32_t seq = htonl(pHead->seqNum); + code = cliGetReqBySeq(conn, seq, &pReq); if (code != 0) { - if (cliConnRmReleaseReq(conn, pHead)) { - return; - } else { - } tDebug("%s conn %p recv unexpected packet, seqNum:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, tstrerror(code)); // TODO: notify cb - if (cliMayRecycleConn(conn)) { return; } return; } - // TODO handle release req - // if (cliRecvReleaseReq(conn, pHead)) { - // return; - // } - STransMsg resp = {0}; code = cliBuildRespFromCont(pReq, &resp, pHead); + STraceId* trace = &resp.info.traceId; if (code != 0) { - tDebug("%s conn %p recv invalid packet, seq %d not found", CONN_GET_INST_LABEL(conn), conn, seq); + tGDebug("%s conn %p recv invalid packet, seq %d not found", CONN_GET_INST_LABEL(conn), conn, seq); } else { - tDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%d", CONN_GET_INST_LABEL(conn), conn, - TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%d, qid:%ld", CONN_GET_INST_LABEL(conn), conn, + TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); } code = cliNotifyCb(conn, pReq, &resp); @@ -571,122 +611,6 @@ void cliHandleResp2(SCliConn* conn) { (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } -// void cliHandleResp(SCliConn* conn) { -// int32_t code = 0; -// SCliThrd* pThrd = conn->hostThrd; -// STrans* pInst = pThrd->pInst; - -// cliResetConnTimer(conn); - -// STransMsgHead* pHead = NULL; - -// int8_t resetBuf = conn->status == ConnAcquire ? 0 : 1; -// int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, resetBuf); -// if (msgLen <= 0) { -// taosMemoryFree(pHead); -// tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); -// // TODO: notify cb -// pThrd->notifyExceptCb(pThrd, NULL, NULL); -// return; -// } - -// if (resetBuf == 0) { -// tTrace("%s conn %p not reset read buf", transLabel(pInst), conn); -// } - -// if ((code = transDecompressMsg((char**)&pHead, msgLen)) < 0) { -// tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); -// // TODO: notify cb -// } -// pHead->code = htonl(pHead->code); -// pHead->msgLen = htonl(pHead->msgLen); -// if (cliRecvReleaseReq(conn, pHead)) { -// return; -// } - -// STransMsg transMsg = {0}; -// transMsg.contLen = transContLenFromMsg(pHead->msgLen); -// transMsg.pCont = transContFromHead((char*)pHead); -// transMsg.code = pHead->code; -// transMsg.msgType = pHead->msgType; -// transMsg.info.ahandle = NULL; -// transMsg.info.traceId = pHead->traceId; -// transMsg.info.hasEpSet = pHead->hasEpSet; -// transMsg.info.cliVer = htonl(pHead->compatibilityVer); - -// SCliReq* pReq = NULL; -// SReqCtx* pCtx = NULL; -// if (CONN_NO_PERSIST_BY_APP(conn)) { -// pReq = transQueuePop(&conn->reqs); - -// pCtx = pReq ? pReq->ctx : NULL; -// transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; -// tDebug("%s conn %p get ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); -// } else { -// uint64_t ahandle = (uint64_t)pHead->ahandle; -// CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); -// if (pReq == NULL) { -// transMsg.info.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType); -// tDebug("%s conn %p construct ahandle %p by %s, persist: 1", CONN_GET_INST_LABEL(conn), conn, -// transMsg.info.ahandle, TMSG_INFO(transMsg.msgType)); -// if (!CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) { -// transMsg.code = TSDB_CODE_RPC_BROKEN_LINK; -// transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType)); -// tDebug("%s conn %p construct ahandle %p due brokenlink, persist: 1", CONN_GET_INST_LABEL(conn), conn, -// transMsg.info.ahandle); -// } -// } else { -// pCtx = pReq->ctx; -// transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL; -// tDebug("%s conn %p get ahandle %p, persist: 1", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle); -// } -// } -// // buf's mem alread translated to transMsg.pCont -// if (!CONN_NO_PERSIST_BY_APP(conn)) { -// transMsg.info.handle = (void*)conn->refId; -// transMsg.info.refId = (int64_t)(void*)conn->refId; -// tDebug("%s conn %p ref by app", CONN_GET_INST_LABEL(conn), conn); -// } - -// STraceId* trace = &transMsg.info.traceId; -// tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, code str:%s", CONN_GET_INST_LABEL(conn), conn, -// TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, tstrerror(transMsg.code)); - -// if (pCtx == NULL && CONN_NO_PERSIST_BY_APP(conn)) { -// tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn); -// transFreeMsg(transMsg.pCont); -// return; -// } -// if (CONN_RELEASE_BY_SERVER(conn) && transMsg.info.ahandle == NULL) { -// tDebug("%s except, conn %p read while cli ignore it", CONN_GET_INST_LABEL(conn), conn); -// transFreeMsg(transMsg.pCont); -// return; -// } - -// if (pReq == NULL || (pReq && pReq->type != Release)) { -// if (cliNotifyCb(conn, pReq, &transMsg) != 0) { -// return; -// } -// } -// int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); -// tDebug("conn %p msg refId: %" PRId64 "", conn, refId); -// destroyReq(pReq); - -// if (cliConnSendSeqMsg(refId, conn)) { -// return; -// } - -// if (cliMaySendCachedMsg(conn) == true) { -// return; -// } - -// if (CONN_NO_PERSIST_BY_APP(conn)) { -// return addConnToPool(pThrd->pool, conn); -// } - -// (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); -// } - void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { // if (transQueueEmpty(&pConn->reqs)) { // if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { @@ -1266,12 +1190,7 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); - if (pReq->msg.info.handle != 0) { - // SExHandle *p = transAcquireExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); - // TAOS_CHECK_GOTO(specifyConnRef(pConn, false, pReq->msg.info.handle), NULL, _exception); - // } else { - // TAOS_CHECK_GOTO(allocConnRef(pConn, false), NULL, _exception); - } + code = cliMayUpdateState(pThrd, pReq, pConn); transQueuePush(&pConn->reqs, pReq); return cliDoConn(pThrd, pConn); @@ -1316,11 +1235,13 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int QUEUE_INIT(&conn->q); conn->hostThrd = pThrd; - conn->status = ConnNormal; - conn->broken = false; transRefCliHandle(conn); conn->seq = 0; + conn->pQTable = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + if (conn->pQTable == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _failed); + } TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); TAOS_CHECK_GOTO(cliGetConnTimer(pThrd, conn), &lino, _failed); @@ -1347,6 +1268,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int _failed: if (conn) { taosMemoryFree(conn->stream); + taosHashCleanup(conn->pQTable); (void)transDestroyBuffer(&conn->readBuf); transQueueDestroy(&conn->reqs); taosMemoryFree(conn->dstAddr); @@ -1405,15 +1327,15 @@ static void cliDestroy(uv_handle_t* handle) { (void)transReleaseExHandle(transGetRefMgt(), conn->refId); (void)transRemoveExHandle(transGetRefMgt(), conn->refId); } + delConnFromHeapCache(pThrd->connHeapCache, conn); taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); cliDestroyConnMsgs(conn, true); - delConnFromHeapCache(pThrd->connHeapCache, conn); - tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); transReqQueueClear(&conn->wreqQueue); + taosHashCleanup(conn->pQTable); (void)transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); @@ -1457,6 +1379,7 @@ static void cliConnRmReqs(SCliConn* conn) { if (pReq->sent == 1 && REQUEST_NO_RESP(&pReq->msg)) { transQueueRm(&conn->reqs, i); destroyReq(pReq); + i--; } } } @@ -1536,6 +1459,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { } pHead->timestamp = taosHton64(taosGetTimestampUs()); pHead->seqNum = htonl(pConn->seq); + pHead->qid = taosHton64(pReq->info.qId); if (pHead->comp == 0) { if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { @@ -1552,8 +1476,8 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pCliMsg->seq = pConn->seq; STraceId* trace = &pCliMsg->msg.info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d", CONN_GET_INST_LABEL(pConn), pConn, - TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq); + tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d, qid:%ld", CONN_GET_INST_LABEL(pConn), pConn, + TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); } if (j == 0) { taosMemoryFree(wb); @@ -1571,7 +1495,11 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; transQueuePush(&pConn->reqs, pCliMsg); - code = cliSend2(pConn); + if (pConn->connnected) { + code = cliSend2(pConn); + } else { + // do nothing + } return code; } @@ -1734,6 +1662,7 @@ void cliConnCb(uv_connect_t* req, int status) { // } return; } + pConn->connnected = 1; cliConnSetSockInfo(pConn); @@ -2012,40 +1941,74 @@ int32_t cliConnHandleQueryById(SCliReq* pReq) { int64_t queryId = (int64_t)pReq->msg.info.handle; SExHandle* exh = transAcquireExHandle(transGetRefMgt(), queryId); if (exh->inited == 1) { - } else { } transReleaseExHandle(transGetRefMgt(), queryId); } return 0; } + +int32_t cliMayGetHandleState(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { + int32_t code = 0; + int64_t qid = pReq->msg.info.qId; + if (qid == 0) { + return TSDB_CODE_RPC_NO_STATE; + } + + SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); + if (pState == NULL) { + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + } else { + *pConn = pState->conn; + } + return code; +} + +int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { + int32_t code = 0; + int64_t qid = pReq->msg.info.qId; + if (qid == 0) { + return TSDB_CODE_RPC_NO_STATE; + } + SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); + if (pState != 0) { + ASSERT(0); + } + SReqState state = {.conn = pConn, .arg = NULL}; + code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); + return code; +} void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { int32_t lino = 0; STransMsg resp = {0}; int32_t code = (pThrd->initCb)(pThrd, pReq, NULL); TAOS_CHECK_GOTO(code, &lino, _exception); - char addr[TSDB_FQDN_LEN + 64] = {0}; - char* ip = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); - int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); - CONN_CONSTRUCT_HASH_KEY(addr, ip, port); - STrans* pInst = pThrd->pInst; SCliConn* pConn = NULL; + code = cliMayGetHandleState(pThrd, pReq, &pConn); - pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); - if (pConn == NULL) { - code = cliGetOrCreateConn(pThrd, pReq, &pConn); - if (code == TSDB_CODE_RPC_MAX_SESSIONS) { - TAOS_CHECK_GOTO(code, &lino, _exception); - } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { - // do nothing, notiy - return; - } else { - ASSERT(code == 0); - addConnToHeapCache(pThrd->connHeapCache, pConn); + if (code == TSDB_CODE_RPC_NO_STATE || code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + char addr[TSDB_FQDN_LEN + 64] = {0}; + char* ip = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); + int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); + CONN_CONSTRUCT_HASH_KEY(addr, ip, port); + + pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); + if (pConn == NULL) { + code = cliGetOrCreateConn(pThrd, pReq, &pConn); + if (code == TSDB_CODE_RPC_MAX_SESSIONS) { + TAOS_CHECK_GOTO(code, &lino, _exception); + } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + // do nothing, notiy + return; + } else { + ASSERT(code == 0); + addConnToHeapCache(pThrd->connHeapCache, pConn); + } } } + code = cliMayUpdateState(pThrd, pReq, pConn); code = cliSendReq(pConn, pReq); tTrace("%s conn %p ready", pInst->label, pConn); @@ -2550,6 +2513,11 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } + pThrd->pIdConnTable = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + if (pThrd->connHeapCache == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + pThrd->initCb = initCb; pThrd->notifyCb = notfiyCb; pThrd->notifyExceptCb = notifyExceptCb; @@ -2576,6 +2544,7 @@ _end: taosHashCleanup(pThrd->fqdn2ipCache); taosHashCleanup(pThrd->failFastCache); taosHashCleanup(pThrd->batchCache); + taosHashCleanup(pThrd->pIdConnTable); taosMemoryFree(pThrd); } @@ -2632,6 +2601,8 @@ static void destroyThrdObj(SCliThrd* pThrd) { } taosHashCleanup(pThrd->connHeapCache); + taosHashCleanup(pThrd->pIdConnTable); + taosMemoryFree(pThrd); } @@ -3111,24 +3082,26 @@ int32_t transReleaseCliHandle(void* handle) { return TSDB_CODE_RPC_BROKEN_LINK; } - STransMsg tmsg = {.info.handle = handle, .info.ahandle = (void*)0x9527}; + STransMsg tmsg = {.msgType = TDMT_SCH_TASK_RELEASE, + .info.handle = handle, + .info.ahandle = (void*)0x9527, + .info.qId = (int64_t)handle}; TRACE_SET_MSGID(&tmsg.info.traceId, tGenIdPI64()); SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - pCtx->ahandle = tmsg.info.ahandle; - SCliReq* cmsg = taosMemoryCalloc(1, sizeof(SCliReq)); + if (cmsg == NULL) { taosMemoryFree(pCtx); return TSDB_CODE_OUT_OF_MEMORY; } cmsg->msg = tmsg; cmsg->st = taosGetTimestampUs(); - cmsg->type = Release; + cmsg->type = Normal; cmsg->ctx = pCtx; STraceId* trace = &tmsg.info.traceId; @@ -3188,31 +3161,7 @@ int32_t transSendRequest(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, TAOS_CHECK_GOTO(TSDB_CODE_RPC_BROKEN_LINK, NULL, _exception); } - if (handle != 0) { - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle); - if (exh != NULL) { - taosWLockLatch(&exh->latch); - if (exh->handle == NULL && exh->inited != 0) { - SCliReq* pCliMsg = NULL; - code = transInitMsg(pInstRef, pEpSet, pReq, ctx, &pCliMsg); - if (code != 0) { - taosWUnLockLatch(&exh->latch); - (void)transReleaseExHandle(transGetRefMgt(), handle); - TAOS_CHECK_GOTO(code, NULL, _exception); - } - - QUEUE_PUSH(&exh->q, &pCliMsg->seqq); - taosWUnLockLatch(&exh->latch); - tDebug("msg refId: %" PRId64 "", handle); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); - return 0; - } else { - exh->inited = 1; - taosWUnLockLatch(&exh->latch); - (void)transReleaseExHandle(transGetRefMgt(), handle); - } - } - } + pReq->info.qId = handle; SCliReq* pCliMsg = NULL; TAOS_CHECK_GOTO(transInitMsg(pInstRef, pEpSet, pReq, ctx, &pCliMsg), NULL, _exception); @@ -3259,6 +3208,7 @@ int32_t transSendRequestWithId(void* pInstRef, const SEpSet* pEpSet, STransMsg* } pReq->info.handle = (void*)(*transpointId); + pReq->info.qId = *transpointId; SCliReq* pCliMsg = NULL; TAOS_CHECK_GOTO(transInitMsg(pInstRef, pEpSet, pReq, NULL, &pCliMsg), NULL, _exception); @@ -3597,6 +3547,7 @@ int32_t transFreeConnById(void* pInstRef, int64_t transpointId) { tDebug("release conn id %" PRId64 "", transpointId); STransMsg msg = {.info.handle = (void*)transpointId}; + msg.info.qId = transpointId; pCli->msg = msg; code = transAsyncSend(pThrd->asyncPool, &pCli->q); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 85d064b68f..ad080f655a 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -71,7 +71,7 @@ typedef struct SSvrMsg { int32_t seqNum; void* arg; FilteFunc func; - + int8_t sent; } SSvrMsg; typedef struct { @@ -423,16 +423,40 @@ static int8_t uvValidConn(SSvrConn* pConn) { } return forbiddenIp; } -static void uvMaySetConnAcquired(SSvrConn* pConn, STransMsgHead* pHead) { - if (pConn->status == ConnNormal) { - if (pHead->persist == 1) { - pConn->status = ConnAcquire; - transRefSrvHandle(pConn); - tDebug("conn %p acquired by server app", pConn); - } else if (pHead->noResp == 0) { - transRefSrvHandle(pConn); + +static int32_t uvHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { + int32_t code = 0; + STrans* pInst = pConn->pInst; + if (pHead->msgType == TDMT_SCH_TASK_RELEASE) { + int64_t qId = taosHton64(pHead->qid); + void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); + if (p == NULL) { + code = TSDB_CODE_RPC_NO_STATE; + tTrace("conn %p recv release, and releady release by server qid%ld", pConn, qId); + // notify cli already release, cli release resouce + } else { + SSvrRegArg* arg = p; + (pInst->cfp)(pInst->parent, &(arg->msg), NULL); + tTrace("conn %p recv release, notify server app, qid%ld", pConn, qId); + (void)taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); } + + STransMsg tmsg = {.code = code, + .msgType = pHead->msgType + 1, + .info.qId = qId, + .info.traceId = pHead->traceId, + .info.seqNum = htonl(pHead->seqNum)}; + SSvrMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrMsg)); + srvMsg->msg = tmsg; + srvMsg->type = Normal; + srvMsg->pConn = pConn; + + transQueuePush(&pConn->srvMsgs, srvMsg); + + uvStartSendRespImpl(srvMsg); + return 1; } + return 0; } static bool uvHandleReq(SSvrConn* pConn) { STrans* pInst = pConn->pInst; @@ -440,8 +464,8 @@ static bool uvHandleReq(SSvrConn* pConn) { STransMsgHead* pHead = NULL; - int8_t resetBuf = pConn->status == ConnAcquire ? 0 : 1; - int msgLen = transDumpFromBuffer(&pConn->readBuf, (char**)&pHead, resetBuf); + int8_t resetBuf = 0; + int msgLen = transDumpFromBuffer(&pConn->readBuf, (char**)&pHead, 0); if (msgLen <= 0) { tError("%s conn %p read invalid packet", transLabel(pInst), pConn); return false; @@ -469,7 +493,7 @@ static bool uvHandleReq(SSvrConn* pConn) { } } - if (uvRecvReleaseReq(pConn, pHead)) { + if (uvHandleReleaseReq(pConn, pHead)) { return true; } @@ -478,14 +502,14 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.pCont = pHead->content; transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; - transMsg.info.qId = htole64(pHead->qid); + transMsg.info.qId = taosHton64(pHead->qid); if (transMsg.info.qId > 0) { - int32_t code = taosHashPut(pConn->pQTable, &transMsg.info.qId, sizeof(int64_t), &transMsg, sizeof(STransMsg)); - if (code != 0) { - tError("%s conn %p failed to put msg to req dict, since %s", transLabel(pInst), pConn, tstrerror(code)); - return false; - } + // int32_t code = taosHashPut(pConn->pQTable, &transMsg.info.qId, sizeof(int64_t), &transMsg, sizeof(STransMsg)); + // if (code != 0) { + // tError("%s conn %p failed to put msg to req dict, since %s", transLabel(pInst), pConn, tstrerror(code)); + // return false; + // } } if (pHead->seqNum == 0) { @@ -595,49 +619,21 @@ void uvOnSendCb(uv_write_t* req, int status) { if (conn == NULL) return; if (status == 0) { - tTrace("conn %p data already was written on stream", conn); - if (!transQueueEmpty(&conn->srvMsgs)) { - SSvrMsg* msg = transQueuePop(&conn->srvMsgs); - STraceId* trace = &msg->msg.info.traceId; - tGDebug("conn %p write data out", conn); - - destroySmsg(msg); - // send cached data - if (!transQueueEmpty(&conn->srvMsgs)) { - msg = (SSvrMsg*)transQueueGet(&conn->srvMsgs, 0); - if (msg->type == Register && conn->status == ConnAcquire) { - if (conn->regArg.init) { - transFreeMsg(conn->regArg.msg.pCont); - conn->regArg.init = 0; - } - conn->regArg.notifyCount = 0; - conn->regArg.init = 1; - conn->regArg.msg = msg->msg; - if (conn->broken) { - STrans* pInst = conn->pInst; - (pInst->cfp)(pInst->parent, &(conn->regArg.msg), NULL); - memset(&conn->regArg, 0, sizeof(conn->regArg)); - } - (void)transQueuePop(&conn->srvMsgs); - taosMemoryFree(msg); - - msg = (SSvrMsg*)transQueueGet(&conn->srvMsgs, 0); - if (msg != NULL) { - uvStartSendRespImpl(msg); - } - } else { - uvStartSendRespImpl(msg); - } + for (int32_t i = 0; i < transQueueSize(&conn->srvMsgs); i++) { + SSvrMsg* smsg = transQueueGet(&conn->srvMsgs, i); + if (smsg->sent == 1) { + transQueueRm(&conn->srvMsgs, i); + destroySmsg(smsg); + i--; } } - transUnrefSrvHandle(conn); } else { if (!uv_is_closing((uv_handle_t*)(conn->pTcp))) { tError("conn %p failed to write data, %s", conn, uv_err_name(status)); conn->broken = true; - transUnrefSrvHandle(conn); } } + transUnrefSrvHandle(conn); } static void uvOnPipeWriteCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); @@ -662,7 +658,6 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { if (pMsg->pCont == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - pMsg->contLen = 0; } STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); @@ -673,30 +668,18 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { pHead->compatibilityVer = htonl(((STrans*)pConn->pInst)->compatibilityVer); pHead->version = TRANS_VER; pHead->seqNum = htonl(pMsg->info.seqNum); + pHead->qid = taosHton64(pMsg->info.qId); // handle invalid drop_task resp, TD-20098 if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { - (void)transQueuePop(&pConn->srvMsgs); - destroySmsg(smsg); - return TSDB_CODE_INVALID_MSG; + ASSERT(0); + // (void)transQueuePop(&pConn->srvMsgs); + // destroySmsg(smsg); + // return TSDB_CODE_INVALID_MSG; } - // if (pConn->status == ConnNormal) { - // pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); - // if (smsg->type == Release) pHead->msgType = 0; - // } else { - // if (smsg->type == Release) { - // pHead->msgType = 0; - // pConn->status = ConnNormal; - // destroyConnRegArg(pConn); - // transUnrefSrvHandle(pConn); - // } else { - // // set up resp msg type - // pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); - // } - // } - pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); + // pHead->msgType = pMsg->msgType; pHead->release = smsg->type == Release ? 1 : 0; pHead->code = htonl(pMsg->code); pHead->msgLen = htonl(pMsg->contLen + sizeof(STransMsgHead)); @@ -712,22 +695,60 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { } STraceId* trace = &pMsg->info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d", transLabel(pInst), pConn, TMSG_INFO(pHead->msgType), - pConn->dst, pConn->src, len); + tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d, seqNum:%d, qid:%ld", transLabel(pInst), pConn, + TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, len, pMsg->info.seqNum, pMsg->info.qId); wb->base = (char*)pHead; wb->len = len; return 0; } +static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* bufNum) { + int32_t count = 0; + + int32_t size = transQueueSize(&pConn->srvMsgs); + uv_buf_t* pWb = taosMemoryCalloc(size, sizeof(uv_buf_t)); + if (pWb == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + for (int32_t i = 0; i < size; i++) { + SSvrMsg* pMsg = transQueueGet(&pConn->srvMsgs, i); + if (pMsg->sent == 1) { + continue; + } + uv_buf_t wb; + (void)uvPrepareSendData(pMsg, &wb); + pWb[count] = wb; + + pMsg->sent = 1; + count++; + } + + if (count == 0) { + taosMemoryFree(pWb); + return 0; + } + + *bufNum = count; + *ppBuf = pWb; + + return 0; +} static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { + int32_t code = 0; SSvrConn* pConn = smsg->pConn; if (pConn->broken) { return; } - uv_buf_t wb; - if (uvPrepareSendData(smsg, &wb) < 0) { + uv_buf_t* pBuf = NULL; + int32_t bufNum = 0; + code = uvBuildToSendData(pConn, &pBuf, &bufNum); + if (code != 0) { + tError("%s conn %p failed to send data", transLabel(pConn->pInst), pConn); + return; + } + if (bufNum == 0) { return; } @@ -741,24 +762,33 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { return; } } - (void)uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); + (void)uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); + taosMemoryFree(pBuf); +} +int32_t uvConnMayHandlsReleaseMsg(SSvrMsg* pMsg) { + SSvrConn* pConn = pMsg->pConn; + if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE) { + int64_t qid = pMsg->msg.info.qId; + SSvrRegArg* p = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); + if (p == NULL) { + tError("%s conn %p already release qid %ld", transLabel(pConn->pInst), pConn, qid); + return TSDB_CODE_RPC_NO_STATE; + } else { + transFreeMsg(p->msg.pCont); + taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); + } + } + return 0; } static void uvStartSendResp(SSvrMsg* smsg) { // impl SSvrConn* pConn = smsg->pConn; - if (pConn->broken == true) { - // persist by + if (uvConnMayHandlsReleaseMsg(smsg) == TSDB_CODE_RPC_NO_STATE) { destroySmsg(smsg); - transUnrefSrvHandle(pConn); return; } - if (pConn->status == ConnNormal) { - transUnrefSrvHandle(pConn); - } - if (!transQueuePush(&pConn->srvMsgs, smsg)) { - return; - } + transQueuePush(&pConn->srvMsgs, smsg); uvStartSendRespImpl(smsg); return; } @@ -1199,7 +1229,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { transRefSrvHandle(pConn); tTrace("%s handle %p, conn %p created, refId:%" PRId64, transLabel(pInst), exh, pConn, pConn->refId); - pConn->pQTable = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + pConn->pQTable = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); if (pConn->pQTable == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); } @@ -1540,19 +1570,20 @@ 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) { - if (!transQueuePush(&conn->srvMsgs, msg)) { - return; - } - uvStartSendRespImpl(msg); - return; - } else if (conn->status == ConnRelease || conn->status == ConnNormal) { - tDebug("%s conn %p already released, ignore release-msg", transLabel(thrd->pInst), conn); - } + ASSERT(0); + // int32_t code = 0; + // SSvrConn* conn = msg->pConn; + // if (conn->status == ConnAcquire) { + // if (!transQueuePush(&conn->srvMsgs, msg)) { + // return; + // } + // uvStartSendRespImpl(msg); + // return; + // } else if (conn->status == ConnRelease || conn->status == ConnNormal) { + // tDebug("%s conn %p already released, ignore release-msg", transLabel(thrd->pInst), conn); + // } - destroySmsg(msg); + // destroySmsg(msg); } void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd) { // send msg to client @@ -1697,6 +1728,7 @@ int32_t transReleaseSrvHandle(void* handle) { int32_t code = 0; SRpcHandleInfo* info = handle; SExHandle* exh = info->handle; + int64_t qId = info->qId; int64_t refId = info->refId; ASYNC_CHECK_HANDLE(info->refIdMgt, refId, exh); @@ -1704,7 +1736,8 @@ int32_t transReleaseSrvHandle(void* handle) { SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); - STransMsg tmsg = {.code = 0, .info.handle = exh, .info.ahandle = NULL, .info.refId = refId}; + STransMsg tmsg = { + .msgType = TDMT_SCH_TASK_RELEASE, .code = 0, .info.handle = exh, .info.ahandle = NULL, .info.refId = refId}; SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); if (m == NULL) { @@ -1713,9 +1746,10 @@ int32_t transReleaseSrvHandle(void* handle) { } m->msg = tmsg; - m->type = Release; + m->type = Normal; - tDebug("%s conn %p start to release", transLabel(pThrd->pInst), exh->handle); + tDebug("%s conn %p start to %p, qId:%" PRId64 "", transLabel(pThrd->pInst), exh->handle, TMSG_INFO(tmsg.msgType), + qId); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); (void)transReleaseExHandle(info->refIdMgt, refId); diff --git a/source/util/src/terror.c b/source/util/src/terror.c index e03913d0e7..8cec54ee68 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -60,6 +60,7 @@ 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") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_IN_PROCESS, "rpc async in process") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NO_STATE, "rpc no state") //common & util TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized") From 5ae6b83d0e10a9bae709284a2e101788e9d836b3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 7 Sep 2024 20:08:48 +0800 Subject: [PATCH 052/240] opt transport --- source/libs/transport/src/transCli.c | 110 ++++++++++++++++----------- source/libs/transport/src/transSvr.c | 42 ++++++---- 2 files changed, 91 insertions(+), 61 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 90b47e1ef8..a11e362cb6 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -209,7 +209,7 @@ static void cliSendBatchCb(uv_write_t* req, int status); SCliBatch* cliGetHeadFromList(SCliBatchList* pList); -static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); +// static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); static int32_t allocConnRef(SCliConn* conn, bool update); @@ -508,12 +508,15 @@ int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHe pResp->info.hasEpSet = pHead->hasEpSet; pResp->info.cliVer = htonl(pHead->compatibilityVer); pResp->info.seqNum = htonl(pHead->seqNum); + + int64_t qid = taosHton64(pHead->qid); + pResp->info.handle = (void*)qid; return 0; } int32_t cliConnMayHandleReleasReq(SCliConn* conn, STransMsgHead* pHead) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; - if (pHead->msgType == TDMT_SCH_TASK_RELEASE) { + if (pHead->msgType == TDMT_SCH_TASK_RELEASE || pHead->msgType == TDMT_SCH_TASK_RELEASE + 1) { int64_t qId = taosHton64(pHead->qid); code = taosHashRemove(conn->pQTable, &qId, sizeof(qId)); if (code != 0) { @@ -524,7 +527,8 @@ int32_t cliConnMayHandleReleasReq(SCliConn* conn, STransMsgHead* pHead) { if (code != 0) { tDebug("%s conn %p failed to release req %ld from thrd ", CONN_GET_INST_LABEL(conn), conn, qId); } - tDebug("%s conn %p release req %ld", CONN_GET_INST_LABEL(conn), conn, qId); + STraceId* trace = &pHead->traceId; + tGDebug("%s conn %p receive release req, qid:%ld", CONN_GET_INST_LABEL(conn), conn, qId); for (int32_t i = 0; i < transQueueSize(&conn->reqs); i++) { SCliReq* pReqs = transQueueGet(&conn->reqs, i); @@ -1957,9 +1961,11 @@ int32_t cliMayGetHandleState(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); if (pState == NULL) { + tDebug("failed to get statue, qid:%ld", qid); return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { *pConn = pState->conn; + tDebug("succ to get conn of statue, qid:%ld", qid); } return code; } @@ -1972,10 +1978,24 @@ int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { } SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); if (pState != 0) { + tDebug("succ to get conn %p of statue, qid:%ld", pConn, qid); ASSERT(0); } SReqState state = {.conn = pConn, .arg = NULL}; code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); + if (code != 0) { + tDebug("failed to add conn %p of statue, qid:%ld", pConn, qid); + } else { + tDebug("succ to add conn %p of statue, qid:%ld (1)", pConn, qid); + } + + int32_t dummy = 0; + code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &dummy, sizeof(dummy)); + if (code != 0) { + tDebug("failed to add conn %p of statue, qid:%ld", pConn, qid); + } else { + tDebug("succ to add conn %p of statue, qid:%ld(2)", pConn, qid); + } return code; } void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { @@ -2007,8 +2027,8 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { addConnToHeapCache(pThrd->connHeapCache, pConn); } } + code = cliMayUpdateState(pThrd, pReq, pConn); } - code = cliMayUpdateState(pThrd, pReq, pConn); code = cliSendReq(pConn, pReq); tTrace("%s conn %p ready", pInst->label, pConn); @@ -2258,51 +2278,50 @@ void cliConnFreeMsgs(SCliConn* conn) { } } -bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead) { - if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { - for (int i = 0; i < transQueueSize(&conn->reqs); i++) { - SCliReq* pReq = transQueueGet(&conn->reqs, i); - if (pHead->ahandle == (uint64_t)pReq->ctx->ahandle) { - tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, conn->refId); - transQueueRm(&conn->reqs, i); - return true; - } - } - } - return false; -} -bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { - if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { - uint64_t ahandle = pHead->ahandle; - SCliReq* pReq = NULL; - CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); - tDebug("%s conn %p receive release request, refId:%" PRId64 ", may ignore", CONN_GET_INST_LABEL(conn), conn, - conn->refId); +// bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead) { +// if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { +// for (int i = 0; i < transQueueSize(&conn->reqs); i++) { +// SCliReq* pReq = transQueueGet(&conn->reqs, i); +// if (pHead->ahandle == (uint64_t)pReq->ctx->ahandle) { +// tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, +// conn->refId); transQueueRm(&conn->reqs, i); return true; +// } +// } +// } +// return false; +// } +// bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { +// if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { +// uint64_t ahandle = pHead->ahandle; +// SCliReq* pReq = NULL; +// CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); +// tDebug("%s conn %p receive release request, refId:%" PRId64 ", may ignore", CONN_GET_INST_LABEL(conn), conn, +// conn->refId); - (void)transClearBuffer(&conn->readBuf); - transFreeMsg(transContFromHead((char*)pHead)); +// (void)transClearBuffer(&conn->readBuf); +// transFreeMsg(transContFromHead((char*)pHead)); - for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->reqs); i++) { - SCliReq* pReq = transQueueGet(&conn->reqs, i); - if (pReq->type == Release) { - ASSERTS(pReq == NULL, "trans-cli recv invaid release-req"); - tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, - conn->refId); - cliDestroyConn(conn, true); - return true; - } - } +// for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->reqs); i++) { +// SCliReq* pReq = transQueueGet(&conn->reqs, i); +// if (pReq->type == Release) { +// ASSERTS(pReq == NULL, "trans-cli recv invaid release-req"); +// tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, +// conn->refId); +// cliDestroyConn(conn, true); +// return true; +// } +// } - cliConnFreeMsgs(conn); +// cliConnFreeMsgs(conn); - tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, conn->refId); - destroyReq(pReq); +// tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, conn->refId); +// destroyReq(pReq); - addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); - return true; - } - return false; -} +// addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); +// return true; +// } +// return false; +// } static FORCE_INLINE void destroyReq(void* arg) { SCliReq* pReq = arg; @@ -3086,6 +3105,7 @@ int32_t transReleaseCliHandle(void* handle) { .info.handle = handle, .info.ahandle = (void*)0x9527, .info.qId = (int64_t)handle}; + TRACE_SET_MSGID(&tmsg.info.traceId, tGenIdPI64()); SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); @@ -3518,7 +3538,7 @@ int32_t transAllocHandle(int64_t* refId) { QUEUE_INIT(&exh->q); taosInitRWLatch(&exh->latch); - tDebug("pre alloc refId %" PRId64 "", exh->refId); + tDebug("alloc qid:%ld", exh->refId); *refId = exh->refId; return 0; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index ad080f655a..e61b0750f9 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -390,21 +390,26 @@ static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* if (pConn->status == ConnNormal && pHead->noResp == 0) { // transRefSrvHandle(pConn); if (cost >= EXCEPTION_LIMIT_US) { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception", transLabel(pInst), - pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception, seqNum:%d, qid:%ld", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus", transLabel(pInst), pConn, - TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, seqNum:%d, qid:%ld", transLabel(pInst), + pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost, + pTransMsg->info.seqNum, pTransMsg->info.qId); } } else { if (cost >= EXCEPTION_LIMIT_US) { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception", - transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, - pHead->noResp, pTransMsg->code, (int)(cost)); + tGDebug( + "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception, " + "seqNum:%d, qid:%ld", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus", transLabel(pInst), - pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, pHead->noResp, - pTransMsg->code, (int)(cost)); + tGDebug( + "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, seqNum:%d, qid:%ld", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); } } tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pInst), pTransMsg->info.handle, pConn, @@ -502,7 +507,6 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.pCont = pHead->content; transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; - transMsg.info.qId = taosHton64(pHead->qid); if (transMsg.info.qId > 0) { // int32_t code = taosHashPut(pConn->pQTable, &transMsg.info.qId, sizeof(int64_t), &transMsg, sizeof(STransMsg)); @@ -531,6 +535,7 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.info.forbiddenIp = forbiddenIp; transMsg.info.noResp = pHead->noResp == 1 ? 1 : 0; transMsg.info.seqNum = htonl(pHead->seqNum); + transMsg.info.qId = taosHton64(pHead->qid); // uvMaySetConnAcquired(pConn, pHead); @@ -767,8 +772,8 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { } int32_t uvConnMayHandlsReleaseMsg(SSvrMsg* pMsg) { SSvrConn* pConn = pMsg->pConn; - if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE) { - int64_t qid = pMsg->msg.info.qId; + int64_t qid = pMsg->msg.info.qId; + if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE && qid > 0) { SSvrRegArg* p = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (p == NULL) { tError("%s conn %p already release qid %ld", transLabel(pConn->pInst), pConn, qid); @@ -1736,8 +1741,13 @@ int32_t transReleaseSrvHandle(void* handle) { SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); - STransMsg tmsg = { - .msgType = TDMT_SCH_TASK_RELEASE, .code = 0, .info.handle = exh, .info.ahandle = NULL, .info.refId = refId}; + STransMsg tmsg = {.msgType = TDMT_SCH_TASK_RELEASE, + .code = 0, + .info.handle = exh, + .info.ahandle = NULL, + .info.refId = refId, + .info.qId = qId, + .info.traceId = info->traceId}; SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); if (m == NULL) { @@ -1748,7 +1758,7 @@ int32_t transReleaseSrvHandle(void* handle) { m->msg = tmsg; m->type = Normal; - tDebug("%s conn %p start to %p, qId:%" PRId64 "", transLabel(pThrd->pInst), exh->handle, TMSG_INFO(tmsg.msgType), + tDebug("%s conn %p start to send %s, qid:%" PRId64 "", transLabel(pThrd->pInst), exh->handle, TMSG_INFO(tmsg.msgType), qId); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); From 488cccd10e7481353e815dc4cd2702621b778ab1 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 8 Sep 2024 06:58:44 +0800 Subject: [PATCH 053/240] opt transport --- source/libs/transport/src/transCli.c | 61 +++++---------------- source/libs/transport/src/transSvr.c | 82 ++++++++++++++-------------- 2 files changed, 53 insertions(+), 90 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a11e362cb6..502cc71cf2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1335,6 +1335,16 @@ static void cliDestroy(uv_handle_t* handle) { taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); + void* pIter = taosHashIterate(conn->pQTable, NULL); + while (pIter) { + int64_t qid = *(int64_t*)pIter; + (void)taosHashRemove(pThrd->pIdConnTable, &qid, sizeof(qid)); + + pIter = taosHashIterate(conn->pQTable, pIter); + + tDebug("%s conn %p destroy state %ld", CONN_GET_INST_LABEL(conn), conn, qid); + } + cliDestroyConnMsgs(conn, true); tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); @@ -2278,51 +2288,6 @@ void cliConnFreeMsgs(SCliConn* conn) { } } -// bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead) { -// if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { -// for (int i = 0; i < transQueueSize(&conn->reqs); i++) { -// SCliReq* pReq = transQueueGet(&conn->reqs, i); -// if (pHead->ahandle == (uint64_t)pReq->ctx->ahandle) { -// tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, -// conn->refId); transQueueRm(&conn->reqs, i); return true; -// } -// } -// } -// return false; -// } -// bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { -// if (pHead->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { -// uint64_t ahandle = pHead->ahandle; -// SCliReq* pReq = NULL; -// CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); -// tDebug("%s conn %p receive release request, refId:%" PRId64 ", may ignore", CONN_GET_INST_LABEL(conn), conn, -// conn->refId); - -// (void)transClearBuffer(&conn->readBuf); -// transFreeMsg(transContFromHead((char*)pHead)); - -// for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->reqs); i++) { -// SCliReq* pReq = transQueueGet(&conn->reqs, i); -// if (pReq->type == Release) { -// ASSERTS(pReq == NULL, "trans-cli recv invaid release-req"); -// tDebug("%s conn %p receive release request, refId:%" PRId64 ", ignore msg", CONN_GET_INST_LABEL(conn), conn, -// conn->refId); -// cliDestroyConn(conn, true); -// return true; -// } -// } - -// cliConnFreeMsgs(conn); - -// tDebug("%s conn %p receive release request, refId:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, conn->refId); -// destroyReq(pReq); - -// addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); -// return true; -// } -// return false; -// } - static FORCE_INLINE void destroyReq(void* arg) { SCliReq* pReq = arg; if (pReq == NULL) { @@ -2330,7 +2295,7 @@ static FORCE_INLINE void destroyReq(void* arg) { } tDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); - destroyReqCtx(pReq->ctx); + if (pReq->ctx) destroyReqCtx(pReq->ctx); transFreeMsg(pReq->msg.pCont); taosMemoryFree(pReq); } @@ -3562,11 +3527,11 @@ int32_t transFreeConnById(void* pInstRef, int64_t transpointId) { if (pCli == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); } - pCli->type = FreeById; + pCli->type = Normal; tDebug("release conn id %" PRId64 "", transpointId); - STransMsg msg = {.info.handle = (void*)transpointId}; + STransMsg msg = {.msgType = TDMT_SCH_TASK_RELEASE, .info.handle = (void*)transpointId}; msg.info.qId = transpointId; pCli->msg = msg; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index e61b0750f9..1bcd8e8324 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -146,8 +146,6 @@ static void uvAcceptAsyncCb(uv_async_t* handle); static void uvShutDownCb(uv_shutdown_t* req, int status); static void uvPrepareCb(uv_prepare_t* handle); -static bool uvRecvReleaseReq(SSvrConn* conn, STransMsgHead* pHead); - /* * time-consuming task throwed into BG work thread */ @@ -429,12 +427,12 @@ static int8_t uvValidConn(SSvrConn* pConn) { return forbiddenIp; } -static int32_t uvHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { +static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { int32_t code = 0; STrans* pInst = pConn->pInst; - if (pHead->msgType == TDMT_SCH_TASK_RELEASE) { - int64_t qId = taosHton64(pHead->qid); - void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); + int64_t qId = taosHton64(pHead->qid); + if (pHead->msgType == TDMT_SCH_TASK_RELEASE && qId > 0) { + void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); if (p == NULL) { code = TSDB_CODE_RPC_NO_STATE; tTrace("conn %p recv release, and releady release by server qid%ld", pConn, qId); @@ -498,7 +496,7 @@ static bool uvHandleReq(SSvrConn* pConn) { } } - if (uvHandleReleaseReq(pConn, pHead)) { + if (uvMayHandleReleaseReq(pConn, pHead)) { return true; } @@ -770,7 +768,7 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { (void)uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); taosMemoryFree(pBuf); } -int32_t uvConnMayHandlsReleaseMsg(SSvrMsg* pMsg) { +int32_t uvMayHandleReleaseResp(SSvrMsg* pMsg) { SSvrConn* pConn = pMsg->pConn; int64_t qid = pMsg->msg.info.qId; if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE && qid > 0) { @@ -788,7 +786,7 @@ int32_t uvConnMayHandlsReleaseMsg(SSvrMsg* pMsg) { static void uvStartSendResp(SSvrMsg* smsg) { // impl SSvrConn* pConn = smsg->pConn; - if (uvConnMayHandlsReleaseMsg(smsg) == TSDB_CODE_RPC_NO_STATE) { + if (uvMayHandleReleaseResp(smsg) == TSDB_CODE_RPC_NO_STATE) { destroySmsg(smsg); return; } @@ -888,40 +886,40 @@ static void uvShutDownCb(uv_shutdown_t* req, int status) { uv_close((uv_handle_t*)req->handle, uvDestroyConn); taosMemoryFree(req); } -static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { - if ((pHead)->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { - tTrace("conn %p received release request", pConn); - STraceId traceId = pHead->traceId; - (void)transClearBuffer(&pConn->readBuf); - transFreeMsg(transContFromHead((char*)pHead)); - if (pConn->status != ConnAcquire) { - return true; - } - pConn->status = ConnRelease; +// static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { +// if ((pHead)->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { +// tTrace("conn %p received release request", pConn); +// STraceId traceId = pHead->traceId; +// (void)transClearBuffer(&pConn->readBuf); +// transFreeMsg(transContFromHead((char*)pHead)); +// if (pConn->status != ConnAcquire) { +// return true; +// } +// pConn->status = ConnRelease; - STransMsg tmsg = {.code = 0, - .info.handle = (void*)pConn, - .info.traceId = traceId, - .info.ahandle = (void*)0x9527, - .info.seqNum = htonl(pHead->seqNum)}; - SSvrMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrMsg)); - srvMsg->msg = tmsg; - srvMsg->type = Release; - srvMsg->pConn = pConn; - if (!transQueuePush(&pConn->srvMsgs, srvMsg)) { - return true; - } - if (pConn->regArg.init) { - tTrace("conn %p release, notify server app", pConn); - STrans* pInst = pConn->pInst; - (*pInst->cfp)(pInst->parent, &(pConn->regArg.msg), NULL); - memset(&pConn->regArg, 0, sizeof(pConn->regArg)); - } - uvStartSendRespImpl(srvMsg); - return true; - } - return false; -} +// STransMsg tmsg = {.code = 0, +// .info.handle = (void*)pConn, +// .info.traceId = traceId, +// .info.ahandle = (void*)0x9527, +// .info.seqNum = htonl(pHead->seqNum)}; +// SSvrMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrMsg)); +// srvMsg->msg = tmsg; +// srvMsg->type = Release; +// srvMsg->pConn = pConn; +// if (!transQueuePush(&pConn->srvMsgs, srvMsg)) { +// return true; +// } +// if (pConn->regArg.init) { +// tTrace("conn %p release, notify server app", pConn); +// STrans* pInst = pConn->pInst; +// (*pInst->cfp)(pInst->parent, &(pConn->regArg.msg), NULL); +// memset(&pConn->regArg, 0, sizeof(pConn->regArg)); +// } +// uvStartSendRespImpl(srvMsg); +// return true; +// } +// return false; +// } static void uvWorkDoTask(uv_work_t* req) { // doing time-consumeing task // only auth conn currently, add more func later From 0b440aad0ccb9cbe5f711ee682440d50d9e10335 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 8 Sep 2024 07:30:16 +0800 Subject: [PATCH 054/240] opt transport --- source/libs/transport/src/transCli.c | 113 +++++++++++++-------------- 1 file changed, 53 insertions(+), 60 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 502cc71cf2..994469ba86 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1147,45 +1147,45 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } } -static int32_t cliAddReqToConn(SCliConn* conn, SCliReq* pReq) { - if (transQueuePush(&conn->reqs, pReq) != 0) { - return TSDB_CODE_OUT_OF_MEMORY; - } - return 0; -} +// static int32_t cliAddReqToConn(SCliConn* conn, SCliReq* pReq) { +// if (transQueuePush(&conn->reqs, pReq) != 0) { +// return TSDB_CODE_OUT_OF_MEMORY; +// } +// return 0; +// } -static int32_t cliRmReqFromConn(SCliConn* conn, SCliReq** pReq) { - // do nothing - SCliReq* pTail = transQueuePop(&conn->reqs); - if (pTail == NULL) { - return TSDB_CODE_INVALID_PARA; - } - if (pReq != NULL) { - *pReq = pTail; - } - return 0; -} -static int32_t cliPutQReqToTable(SCliConn* pConn, SCliReq* pReq) { - int32_t code = 0; - if (pReq->msg.info.handle == 0) { - return 0; - } +// static int32_t cliRmReqFromConn(SCliConn* conn, SCliReq** pReq) { +// // do nothing +// SCliReq* pTail = transQueuePop(&conn->reqs); +// if (pTail == NULL) { +// return TSDB_CODE_INVALID_PARA; +// } +// if (pReq != NULL) { +// *pReq = pTail; +// } +// return 0; +// } +// static int32_t cliPutQReqToTable(SCliConn* pConn, SCliReq* pReq) { +// int32_t code = 0; +// if (pReq->msg.info.handle == 0) { +// return 0; +// } - queue q; - QUEUE_INIT(&q); +// queue q; +// QUEUE_INIT(&q); - queue* p = taosHashGet(pConn->pQueryTable, (void*)pReq->msg.info.handle, sizeof(int64_t)); - if (p == NULL) { - QUEUE_PUSH(&q, &pReq->qlist); - code = taosHashPut(pConn->pQueryTable, (void*)pReq->msg.info.handle, sizeof(int64_t), &q, sizeof(queue)); - if (code != 0) { - return code; - } - } else { - QUEUE_PUSH(p, &pReq->qlist); - } - return 0; -} +// queue* p = taosHashGet(pConn->pQueryTable, (void*)pReq->msg.info.handle, sizeof(int64_t)); +// if (p == NULL) { +// QUEUE_PUSH(&q, &pReq->qlist); +// code = taosHashPut(pConn->pQueryTable, (void*)pReq->msg.info.handle, sizeof(int64_t), &q, sizeof(queue)); +// if (code != 0) { +// return code; +// } +// } else { +// QUEUE_PUSH(p, &pReq->qlist); +// } +// return 0; +// } static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) { int32_t code = 0; SCliConn* pConn = NULL; @@ -1218,18 +1218,11 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int conn->ipStr = taosStrdup(ip); conn->port = port; - transReqQueueInit(&conn->wreqQueue); QUEUE_INIT(&conn->q); conn->hostThrd = pThrd; conn->status = ConnNormal; conn->broken = false; - - conn->pQueryTable = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - TAOS_CHECK_GOTO(transQueueInit(&conn->reqs, NULL), NULL, _failed); - - TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); - - transRefCliHandle(conn); + QUEUE_INIT(&conn->q); transReqQueueInit(&conn->wreqQueue); @@ -1237,9 +1230,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); - QUEUE_INIT(&conn->q); conn->hostThrd = pThrd; - transRefCliHandle(conn); conn->seq = 0; conn->pQTable = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); @@ -1263,10 +1254,11 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int code = TSDB_CODE_THIRDPARTY_ERROR; TAOS_CHECK_GOTO(code, NULL, _failed); } - conn->stream->data = conn; conn->connReq.data = conn; + transRefCliHandle(conn); + *pCliConn = conn; return code; _failed: @@ -1276,6 +1268,9 @@ _failed: (void)transDestroyBuffer(&conn->readBuf); transQueueDestroy(&conn->reqs); taosMemoryFree(conn->dstAddr); + + (void)transReleaseExHandle(transGetRefMgt(), conn->refId); + (void)transRemoveExHandle(transGetRefMgt(), conn->refId); } tError("failed to create conn, code:%d", code); taosMemoryFree(conn); @@ -1286,7 +1281,6 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn); conn->broken = true; QUEUE_REMOVE(&conn->q); - QUEUE_INIT(&conn->q); conn->broken = true; if (conn->list == NULL) { @@ -1334,15 +1328,14 @@ static void cliDestroy(uv_handle_t* handle) { delConnFromHeapCache(pThrd->connHeapCache, conn); taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); + taosMemoryFree(conn->ipStr); void* pIter = taosHashIterate(conn->pQTable, NULL); while (pIter) { - int64_t qid = *(int64_t*)pIter; - (void)taosHashRemove(pThrd->pIdConnTable, &qid, sizeof(qid)); - + int64_t* qid = taosHashGetKey(pIter, NULL); + (void)taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); pIter = taosHashIterate(conn->pQTable, pIter); - - tDebug("%s conn %p destroy state %ld", CONN_GET_INST_LABEL(conn), conn, qid); + tDebug("%s conn %p destroy state %ld", CONN_GET_INST_LABEL(conn), conn, *qid); } cliDestroyConnMsgs(conn, true); @@ -2482,10 +2475,10 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { 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->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) { @@ -2577,11 +2570,11 @@ static void destroyThrdObj(SCliThrd* pThrd) { } taosHashCleanup(pThrd->batchCache); - void** pIter2 = taosHashIterate(pThrd->connHeapCache, NULL); + void* pIter2 = taosHashIterate(pThrd->connHeapCache, NULL); while (pIter2 != NULL) { - SHeap* heap = (SHeap*)(*pIter2); + SHeap* heap = (SHeap*)(pIter2); transHeapDestroy(heap); - pIter2 = (void**)taosHashIterate(pThrd->connHeapCache, pIter2); + pIter2 = (void*)taosHashIterate(pThrd->connHeapCache, pIter2); } taosHashCleanup(pThrd->connHeapCache); From 0b1e54568c5651a8a6d4f84fa256dde217a304b0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 9 Sep 2024 18:42:36 +0800 Subject: [PATCH 055/240] opt transport --- source/common/src/tglobal.c | 58 ++++----- source/libs/transport/inc/transComm.h | 7 +- source/libs/transport/src/transCli.c | 168 +++++++++++++++++--------- source/libs/transport/src/transComm.c | 31 +++-- source/libs/transport/src/transSvr.c | 65 +++++++--- 5 files changed, 210 insertions(+), 119 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index cf0a4725c1..69171892cb 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -177,12 +177,12 @@ int32_t tsRedirectFactor = 2; int32_t tsRedirectMaxPeriod = 1000; int32_t tsMaxRetryWaitTime = 10000; bool tsUseAdapter = false; -int32_t tsMetaCacheMaxSize = -1; // MB -int32_t tsSlowLogThreshold = 10; // seconds -int32_t tsSlowLogThresholdTest = INT32_MAX; // seconds -char tsSlowLogExceptDb[TSDB_DB_NAME_LEN] = ""; // seconds +int32_t tsMetaCacheMaxSize = -1; // MB +int32_t tsSlowLogThreshold = 10; // seconds +int32_t tsSlowLogThresholdTest = INT32_MAX; // seconds +char tsSlowLogExceptDb[TSDB_DB_NAME_LEN] = ""; // seconds int32_t tsSlowLogScope = SLOW_LOG_TYPE_QUERY; -char* tsSlowLogScopeString = "query"; +char *tsSlowLogScopeString = "query"; int32_t tsSlowLogMaxLen = 4096; int32_t tsTimeSeriesThreshold = 50; bool tsMultiResultFunctionStarReturnTags = false; @@ -320,7 +320,6 @@ 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); \ @@ -359,7 +358,7 @@ static int32_t taosSplitS3Cfg(SConfig *pCfg, const char *name, char gVarible[TSD TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, name); char *strDup = NULL; - if ((strDup = taosStrdup(pItem->str))== NULL){ + if ((strDup = taosStrdup(pItem->str)) == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; } @@ -448,7 +447,9 @@ int32_t taosSetS3Cfg(SConfig *pCfg) { TAOS_RETURN(TSDB_CODE_SUCCESS); } -struct SConfig *taosGetCfg() { return tsCfg; } +struct SConfig *taosGetCfg() { + return tsCfg; +} static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) { @@ -596,10 +597,11 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "metaCacheMaxSize", tsMetaCacheMaxSize, -1, INT32_MAX, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "randErrorChance", tsRandErrChance, 0, 10000, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); - TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "randErrorDivisor", tsRandErrDivisor, 1, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); + TAOS_CHECK_RETURN( + cfgAddInt64(pCfg, "randErrorDivisor", tsRandErrDivisor, 1, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "randErrorScope", tsRandErrScope, 0, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); - tsNumOfRpcThreads = tsNumOfCores / 2; + // tsNumOfRpcThreads = tsNumOfCores / 2; tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfRpcThreads", tsNumOfRpcThreads, 1, 1024, CFG_SCOPE_BOTH, CFG_DYN_NONE)); @@ -862,7 +864,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem = cfgGetItem(pCfg, "numOfRpcThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfRpcThreads = numOfCores / 2; + // tsNumOfRpcThreads = numOfCores / 2; tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); pItem->i32 = tsNumOfRpcThreads; pItem->stype = stype; @@ -1072,9 +1074,9 @@ int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope) { int32_t slowScope = 0; - char* scope = NULL; - char *tmp = NULL; - while((scope = strsep(&pScopeStr, "|")) != NULL){ + char *scope = NULL; + char *tmp = NULL; + while ((scope = strsep(&pScopeStr, "|")) != NULL) { taosMemoryFreeClear(tmp); tmp = taosStrdup(scope); (void)strtrim(tmp); @@ -1128,13 +1130,13 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { (void)snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "firstEp"); - SEp firstEp = {0}; + SEp firstEp = {0}; 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, pItem->stype, true)); TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "secondEp"); - SEp secondEp = {0}; + SEp secondEp = {0}; 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, pItem->stype, true)); @@ -1622,8 +1624,8 @@ 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; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SConfig *pCfg = NULL; if (tsCfg == NULL) { @@ -1691,7 +1693,7 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char * TAOS_CHECK_RETURN(cfgInit(&pCfg)); 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); + 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\n", tstrerror(code)); @@ -1720,7 +1722,7 @@ _exit: static int32_t taosCheckGlobalCfg() { uint32_t ipv4 = 0; - int32_t code = taosGetIpv4FromFqdn(tsLocalFqdn, &ipv4); + int32_t code = taosGetIpv4FromFqdn(tsLocalFqdn, &ipv4); if (code) { uError("failed to get ip from fqdn:%s since %s, dnode can not be initialized", tsLocalFqdn, tstrerror(code)); TAOS_RETURN(TSDB_CODE_RPC_FQDN_ERROR); @@ -1825,7 +1827,7 @@ typedef struct { static int32_t taosCfgSetOption(OptionNameAndVar *pOptions, int32_t optionSize, SConfigItem *pItem, bool isDebugflag) { int32_t code = TSDB_CODE_CFG_NOT_FOUND; - char *name = pItem->name; + char *name = pItem->name; for (int32_t d = 0; d < optionSize; ++d) { const char *optName = pOptions[d].optionName; if (strcasecmp(name, optName) != 0) continue; @@ -2012,8 +2014,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { } case 'f': { if (strcasecmp("fqdn", name) == 0) { - SConfigItem* pFqdnItem = cfgGetItem(pCfg, "fqdn"); - SConfigItem* pServerPortItem = cfgGetItem(pCfg, "serverPort"); + 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"); @@ -2028,7 +2030,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { char defaultFirstEp[TSDB_EP_LEN] = {0}; (void)snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - SEp firstEp = {0}; + SEp firstEp = {0}; TAOS_CHECK_GOTO( taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp), &lino, _out); @@ -2068,8 +2070,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { } case 'l': { if (strcasecmp("locale", name) == 0) { - SConfigItem* pLocaleItem = cfgGetItem(pCfg, "locale"); - SConfigItem* pCharsetItem = cfgGetItem(pCfg, "charset"); + SConfigItem *pLocaleItem = cfgGetItem(pCfg, "locale"); + SConfigItem *pCharsetItem = cfgGetItem(pCfg, "charset"); if (pLocaleItem == NULL || pCharsetItem == NULL) { uError("failed to get locale or charset from cfg"); code = TSDB_CODE_CFG_NOT_FOUND; @@ -2147,7 +2149,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { char defaultFirstEp[TSDB_EP_LEN] = {0}; (void)snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - SEp firstEp = {0}; + SEp firstEp = {0}; TAOS_CHECK_GOTO( taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp), &lino, _out); @@ -2275,7 +2277,7 @@ int32_t taosSetGlobalDebugFlag(int32_t flag) { return taosSetAllDebugFlag(tsCfg, // NOTE: set all command does not change the tmrDebugFlag static int32_t taosSetAllDebugFlag(SConfig *pCfg, int32_t flag) { if (flag < 0) TAOS_RETURN(TSDB_CODE_INVALID_PARA); - if (flag == 0) TAOS_RETURN(TSDB_CODE_SUCCESS); // just ignore + if (flag == 0) TAOS_RETURN(TSDB_CODE_SUCCESS); // just ignore SArray *noNeedToSetVars = NULL; SConfigItem *pItem = NULL; diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 078ede9d73..4c5b1511b2 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -351,12 +351,13 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType); // request list typedef struct STransReq { - queue q; - uv_write_t wreq; + queue q; + queue node; + void* conn; } STransReq; void transReqQueueInit(queue* q); -void* transReqQueuePush(queue* q); +void* transReqQueuePush(queue* q, STransReq* req); void* transReqQueueRemove(void* arg); void transReqQueueClear(queue* q); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 994469ba86..23ed1e78a1 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -154,7 +154,7 @@ typedef struct SCliThrd { int32_t (*notifyCb)(void* arg, SCliReq* pReq, STransMsg* pResp); int32_t (*notifyExceptCb)(void* arg, SCliReq* pReq, STransMsg* pResp); - SHashObj* pIdConnTable; + SHashObj* pIdConnTable; // } SCliThrd; typedef struct SCliObj { @@ -209,6 +209,18 @@ static void cliSendBatchCb(uv_write_t* req, int status); SCliBatch* cliGetHeadFromList(SCliBatchList* pList); +void destroyCliConnQTable(SCliConn* conn) { + void* pIter = taosHashIterate(conn->pQTable, NULL); + while (pIter != NULL) { + int64_t* qid = taosHashGetKey(pIter, NULL); + STransCtx* ctx = pIter; + transCtxCleanup(ctx); + pIter = taosHashIterate(conn->pQTable, pIter); + } + taosHashCleanup(conn->pQTable); + conn->pQTable = NULL; +} + // static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); static int32_t allocConnRef(SCliConn* conn, bool update); @@ -266,7 +278,7 @@ static FORCE_INLINE int cliRBChoseIdx(STrans* pInst); static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx); int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn); -int32_t cliMayGetHandleState(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); +int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); @@ -503,7 +515,9 @@ int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHe pResp->pCont = transContFromHead((char*)pHead); pResp->code = pHead->code; pResp->msgType = pHead->msgType; - pResp->info.ahandle = pReq->ctx ? pReq->ctx->ahandle : NULL; + if (pResp->info.ahandle == 0) { + pResp->info.ahandle = (pReq && pReq->ctx) ? pReq->ctx->ahandle : NULL; + } pResp->info.traceId = pHead->traceId; pResp->info.hasEpSet = pHead->hasEpSet; pResp->info.cliVer = htonl(pHead->compatibilityVer); @@ -513,11 +527,17 @@ int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHe pResp->info.handle = (void*)qid; return 0; } -int32_t cliConnMayHandleReleasReq(SCliConn* conn, STransMsgHead* pHead) { +int32_t cliConnMayHandleState_releaseReq(SCliConn* conn, STransMsgHead* pHead) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; if (pHead->msgType == TDMT_SCH_TASK_RELEASE || pHead->msgType == TDMT_SCH_TASK_RELEASE + 1) { - int64_t qId = taosHton64(pHead->qid); + int64_t qId = taosHton64(pHead->qid); + STraceId* trace = &pHead->traceId; + tGDebug("%s conn %p receive release req, qid:%ld", CONN_GET_INST_LABEL(conn), conn, qId); + + STransCtx* p = taosHashGet(conn->pQTable, &qId, sizeof(qId)); + transCtxCleanup(p); + code = taosHashRemove(conn->pQTable, &qId, sizeof(qId)); if (code != 0) { tDebug("%s conn %p failed to release req %ld from conn", CONN_GET_INST_LABEL(conn), conn, qId); @@ -527,21 +547,41 @@ int32_t cliConnMayHandleReleasReq(SCliConn* conn, STransMsgHead* pHead) { if (code != 0) { tDebug("%s conn %p failed to release req %ld from thrd ", CONN_GET_INST_LABEL(conn), conn, qId); } - STraceId* trace = &pHead->traceId; - tGDebug("%s conn %p receive release req, qid:%ld", CONN_GET_INST_LABEL(conn), conn, qId); + tDebug("%s %p req size:%d", CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqs)); for (int32_t i = 0; i < transQueueSize(&conn->reqs); i++) { - SCliReq* pReqs = transQueueGet(&conn->reqs, i); - if (pReqs->msg.info.qId == qId) { + SCliReq* pReq = transQueueGet(&conn->reqs, i); + if (pReq->msg.info.qId == qId) { transQueueRm(&conn->reqs, i); - destroyReq(pReqs); + + if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { + pThrd->destroyAhandleFp(pReq->ctx->ahandle); + } + destroyReq(pReq); i--; } } + taosMemoryFree(pHead); return 1; } return 0; } +int32_t cliMayHandleState(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp) { + int32_t code = 0; + int64_t qId = taosHton64(pHead->qid); + if (qId == 0) { + return 0; + } + + STransCtx* pCtx = taosHashGet(conn->pQTable, &qId, sizeof(qId)); + if (pCtx == 0) { + return TSDB_CODE_RPC_NO_STATE; + } + pResp->info.ahandle = transCtxDumpVal(pCtx, pHead->msgType); + tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(conn), conn, pResp->info.ahandle, + TMSG_INFO(pHead->msgType)); + return 0; +} void cliHandleResp2(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; @@ -565,33 +605,38 @@ void cliHandleResp2(SCliConn* conn) { // TODO: notify cb return; } - - if (cliConnMayHandleReleasReq(conn, pHead)) { - if (cliMayRecycleConn(conn)) { - return; - } - - return; - } int64_t qId = taosHton64(pHead->qid); - pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); + int32_t seq = htonl(pHead->seqNum); + STransMsg resp = {0}; - int32_t seq = htonl(pHead->seqNum); - - code = cliGetReqBySeq(conn, seq, &pReq); - if (code != 0) { - tDebug("%s conn %p recv unexpected packet, seqNum:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, - tstrerror(code)); - // TODO: notify cb + if (cliConnMayHandleState_releaseReq(conn, pHead)) { if (cliMayRecycleConn(conn)) { return; } return; } + code = cliGetReqBySeq(conn, seq, &pReq); + if (code == TSDB_CODE_OUT_OF_RANGE) { + code = cliMayHandleState(conn, pHead, &resp); + if (code == 0) { + code = cliBuildRespFromCont(NULL, &resp, pHead); + code = cliNotifyCb(conn, NULL, &resp); + return; + } + + if (code != 0) { + tDebug("%s conn %p recv unexpected packet, seqNum:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, + tstrerror(code)); + // TODO: notify cb + if (cliMayRecycleConn(conn)) { + return; + } + return; + } + } - STransMsg resp = {0}; code = cliBuildRespFromCont(pReq, &resp, pHead); STraceId* trace = &resp.info.traceId; if (code != 0) { @@ -1195,8 +1240,9 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); code = cliMayUpdateState(pThrd, pReq, pConn); - transQueuePush(&pConn->reqs, pReq); + addConnToHeapCache(pThrd->connHeapCache, pConn); + transQueuePush(&pConn->reqs, pReq); return cliDoConn(pThrd, pConn); _exception: // free conn @@ -1264,6 +1310,8 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int _failed: if (conn) { taosMemoryFree(conn->stream); + + destroyCliConnQTable(conn); taosHashCleanup(conn->pQTable); (void)transDestroyBuffer(&conn->readBuf); transQueueDestroy(&conn->reqs); @@ -1339,10 +1387,10 @@ static void cliDestroy(uv_handle_t* handle) { } cliDestroyConnMsgs(conn, true); + destroyCliConnQTable(conn); tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); transReqQueueClear(&conn->wreqQueue); - taosHashCleanup(conn->pQTable); (void)transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); @@ -1673,7 +1721,7 @@ void cliConnCb(uv_connect_t* req, int status) { cliConnSetSockInfo(pConn); - addConnToHeapCache(pThrd->connHeapCache, pConn); + // addConnToHeapCache(pThrd->connHeapCache, pConn); tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); (void)cliSend2(pConn); @@ -1941,21 +1989,22 @@ static void doFreeTimeoutMsg(void* param) { taosMemoryFree(arg); } -int32_t cliConnHandleQueryById(SCliReq* pReq) { - if (pReq->msg.info.handle == 0) { - return 0; +int32_t clConnMayUpdateReqCtx(SCliConn* pConn, SCliReq* pReq) { + int32_t code = 0; + int64_t qid = pReq->msg.info.qId; + SReqCtx* pCtx = pReq->ctx; + + STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); + if (pUserCtx == NULL) { + code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &pCtx->userCtx, sizeof(pCtx->userCtx)); + tDebug("succ to add conn %p of statue ctx, qid:%ld", pConn, qid); } else { - int64_t queryId = (int64_t)pReq->msg.info.handle; - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), queryId); - if (exh->inited == 1) { - } else { - } - transReleaseExHandle(transGetRefMgt(), queryId); + transCtxMerge(pUserCtx, &pCtx->userCtx); + tDebug("succ to update conn %p of statue ctx, qid:%ld", pConn, qid); } return 0; } - -int32_t cliMayGetHandleState(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { +int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { int32_t code = 0; int64_t qid = pReq->msg.info.qId; if (qid == 0) { @@ -1965,12 +2014,13 @@ int32_t cliMayGetHandleState(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); if (pState == NULL) { tDebug("failed to get statue, qid:%ld", qid); + // ASSERT(0); return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { *pConn = pState->conn; tDebug("succ to get conn of statue, qid:%ld", qid); } - return code; + return 0; } int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { @@ -1984,6 +2034,7 @@ int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { tDebug("succ to get conn %p of statue, qid:%ld", pConn, qid); ASSERT(0); } + SReqState state = {.conn = pConn, .arg = NULL}; code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); if (code != 0) { @@ -1992,13 +2043,7 @@ int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { tDebug("succ to add conn %p of statue, qid:%ld (1)", pConn, qid); } - int32_t dummy = 0; - code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &dummy, sizeof(dummy)); - if (code != 0) { - tDebug("failed to add conn %p of statue, qid:%ld", pConn, qid); - } else { - tDebug("succ to add conn %p of statue, qid:%ld(2)", pConn, qid); - } + (void)clConnMayUpdateReqCtx(pConn, pReq); return code; } void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { @@ -2009,7 +2054,10 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { STrans* pInst = pThrd->pInst; SCliConn* pConn = NULL; - code = cliMayGetHandleState(pThrd, pReq, &pConn); + code = cliMayGetStateByQid(pThrd, pReq, &pConn); + if (code == 0) { + (void)clConnMayUpdateReqCtx(pConn, pReq); + } if (code == TSDB_CODE_RPC_NO_STATE || code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { char addr[TSDB_FQDN_LEN + 64] = {0}; @@ -2933,9 +2981,13 @@ void cliMayResetRespCode(SCliReq* pReq, STransMsg* pResp) { int32_t cliNotifyImplCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - SReqCtx* pCtx = pReq->ctx; + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; STraceId* trace = &pResp->info.traceId; + if (pCtx == NULL) { + pInst->cfp(pInst->parent, pResp, NULL); + return 0; + } if (pCtx->pSem || pCtx->syncMsgRef != 0) { tGTrace("%s conn %p(sync) handle resp", CONN_GET_INST_LABEL(pConn), pConn); if (pCtx->pSem) { @@ -2978,14 +3030,16 @@ int32_t cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - if (cliMayRetry(pConn, pReq, pResp)) { - return TSDB_CODE_RPC_ASYNC_IN_PROCESS; - } + if (pReq != NULL) { + if (cliMayRetry(pConn, pReq, pResp)) { + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + } - cliMayResetRespCode(pReq, pResp); + cliMayResetRespCode(pReq, pResp); - if (cliTryUpdateEpset(pReq, pResp)) { - cliPerfLog_epset(pConn, pReq); + if (cliTryUpdateEpset(pReq, pResp)) { + cliPerfLog_epset(pConn, pReq); + } } return cliNotifyImplCb(pConn, pReq, pResp); } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 60058bbbd2..326fd434ec 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -15,7 +15,7 @@ #include "transComm.h" -#define BUFFER_CAP 4096 +#define BUFFER_CAP 16 * 4096 static TdThreadOnce transModuleInit = PTHREAD_ONCE_INIT; @@ -341,7 +341,7 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { void transCtxInit(STransCtx* ctx) { // init transCtx - ctx->args = taosHashInit(2, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UINT), true, HASH_NO_LOCK); + ctx->args = taosHashInit(2, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); } void transCtxCleanup(STransCtx* ctx) { if (ctx->args == NULL) { @@ -350,6 +350,8 @@ void transCtxCleanup(STransCtx* ctx) { STransCtxVal* iter = taosHashIterate(ctx->args, NULL); while (iter) { + int32_t* type = taosHashGetKey(iter, NULL); + tDebug("free msg type %s dump func", TMSG_INFO(*type)); ctx->freeFunc(iter->val); iter = taosHashIterate(ctx->args, iter); } @@ -409,27 +411,22 @@ void transReqQueueInit(queue* q) { // init req queue QUEUE_INIT(q); } -void* transReqQueuePush(queue* q) { - STransReq* req = taosMemoryCalloc(1, sizeof(STransReq)); - if (req == NULL) { - return NULL; - } - req->wreq.data = req; - QUEUE_PUSH(q, &req->q); - return &req->wreq; +void* transReqQueuePush(queue* q, STransReq* userReq) { + uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); + req->data = userReq; + + QUEUE_PUSH(q, &userReq->q); + return req; } void* transReqQueueRemove(void* arg) { void* ret = NULL; - uv_write_t* wreq = arg; + uv_write_t* req = arg; - STransReq* req = wreq ? wreq->data : NULL; + STransReq* userReq = req ? req->data : NULL; if (req == NULL) return NULL; - QUEUE_REMOVE(&req->q); + QUEUE_REMOVE(&userReq->q); - ret = wreq && wreq->handle ? wreq->handle->data : NULL; - taosMemoryFree(req); - - return ret; + return userReq; } void transReqQueueClear(queue* q) { while (!QUEUE_IS_EMPTY(q)) { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 1bcd8e8324..2d70e3e344 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -72,6 +72,9 @@ typedef struct SSvrMsg { void* arg; FilteFunc func; int8_t sent; + + queue sendReq; + } SSvrMsg; typedef struct { @@ -618,17 +621,35 @@ void uvOnTimeoutCb(uv_timer_t* handle) { void uvOnSendCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); - SSvrConn* conn = transReqQueueRemove(req); - if (conn == NULL) return; + + queue q; + QUEUE_INIT(&q); + + STransReq* userReq = transReqQueueRemove(req); + SSvrConn* conn = userReq->conn; + + queue* src = &userReq->node; + while (!QUEUE_IS_EMPTY(src)) { + queue* head = QUEUE_HEAD(src); + QUEUE_REMOVE(head); + QUEUE_PUSH(&q, head); + // } + } + // QUEUE_MOVE(src, &q); + + tDebug("%s conn %p send data", transLabel(conn->pInst), conn); if (status == 0) { - for (int32_t i = 0; i < transQueueSize(&conn->srvMsgs); i++) { - SSvrMsg* smsg = transQueueGet(&conn->srvMsgs, i); - if (smsg->sent == 1) { - transQueueRm(&conn->srvMsgs, i); - destroySmsg(smsg); - i--; - } + while (!QUEUE_IS_EMPTY(&q)) { + queue* head = QUEUE_HEAD(&q); + QUEUE_REMOVE(head); + + SSvrMsg* smsg = QUEUE_DATA(head, SSvrMsg, sendReq); + + STraceId* trace = &smsg->msg.info.traceId; + tGDebug("%s conn %p msg already send out, seqNum:%d, qid:%ld", transLabel(conn->pInst), conn, + smsg->msg.info.seqNum, smsg->msg.info.qId); + destroySmsg(smsg); } } else { if (!uv_is_closing((uv_handle_t*)(conn->pTcp))) { @@ -705,7 +726,7 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { wb->len = len; return 0; } -static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* bufNum) { +static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* bufNum, queue* sendReqNode) { int32_t count = 0; int32_t size = transQueueSize(&pConn->srvMsgs); @@ -713,7 +734,9 @@ static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* buf if (pWb == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - for (int32_t i = 0; i < size; i++) { + + tDebug("%s conn %p has %d msg to send", transLabel(pConn->pInst), pConn, size); + for (int32_t i = 0; i < transQueueSize(&pConn->srvMsgs); i++) { SSvrMsg* pMsg = transQueueGet(&pConn->srvMsgs, i); if (pMsg->sent == 1) { continue; @@ -721,8 +744,12 @@ static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* buf uv_buf_t wb; (void)uvPrepareSendData(pMsg, &wb); pWb[count] = wb; - pMsg->sent = 1; + + QUEUE_PUSH(sendReqNode, &pMsg->sendReq); + + transQueueRm(&pConn->srvMsgs, i); + i--; count++; } @@ -743,20 +770,30 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { if (pConn->broken) { return; } + queue sendReqNode; + QUEUE_INIT(&sendReqNode); uv_buf_t* pBuf = NULL; int32_t bufNum = 0; - code = uvBuildToSendData(pConn, &pBuf, &bufNum); + code = uvBuildToSendData(pConn, &pBuf, &bufNum, &sendReqNode); if (code != 0) { tError("%s conn %p failed to send data", transLabel(pConn->pInst), pConn); return; } if (bufNum == 0) { + tDebug("%s conn %p no data to send", transLabel(pConn->pInst), pConn); return; } transRefSrvHandle(pConn); - uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); + + STransReq* pWreq = taosMemoryCalloc(1, sizeof(STransReq)); + pWreq->conn = pConn; + QUEUE_INIT(&pWreq->q); + + QUEUE_MOVE(&sendReqNode, &pWreq->node); + + uv_write_t* req = transReqQueuePush(&pConn->wreqQueue, pWreq); if (req == NULL) { if (!uv_is_closing((uv_handle_t*)(pConn->pTcp))) { tError("conn %p failed to write data, reason:%s", pConn, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); From 334822f2d882237856c88fbe8d3ed6113d22b4fd Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 9 Sep 2024 20:16:04 +0800 Subject: [PATCH 056/240] opt transport --- source/libs/transport/src/transCli.c | 8 ++++++++ source/libs/transport/src/transSvr.c | 1 + 2 files changed, 9 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 23ed1e78a1..3c74fbd168 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3630,6 +3630,14 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } code = transHeapGet(pHeap, &pConn); + if (pConn && taosHashGetSize(pConn->pQTable) > 0) { + tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); + return NULL; + } /*else { + // tDebug("failed to get conn from heap cache for key:%s", key); + // return NULL; + }*/ + if (code != 0) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 2d70e3e344..2b05ad1a65 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1086,6 +1086,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); + transSetConnOption((uv_tcp_t*)pConn->pTcp, 20); (void)uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); } else { From e656f65d7c0c4758bc7bfb31bc49914c13890a8e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 9 Sep 2024 21:28:42 +0800 Subject: [PATCH 057/240] opt transport --- log | 205 +++++++++++++++++++++++++ qid | 216 +++++++++++++++++++++++++++ source/libs/transport/src/transCli.c | 17 ++- source/libs/transport/src/transSvr.c | 3 + sql0 | 140 +++++++++++++++++ sql1 | 141 +++++++++++++++++ 6 files changed, 715 insertions(+), 7 deletions(-) create mode 100644 log create mode 100644 qid create mode 100644 sql0 create mode 100644 sql1 diff --git a/log b/log new file mode 100644 index 0000000000..de7cd0bfa7 --- /dev/null +++ b/log @@ -0,0 +1,205 @@ +10060:09/09 19:07:23.425713 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +10062:09/09 19:07:23.425770 00161875 C RPC DND-S conn 0x7f73780418e0 heartbeat received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:184, cost:161us, seqNum:9, qid:15, gtid:0xadc8d77787a1000d:0x70b71d6778700015 +10063:09/09 19:07:23.425776 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77787a1000d:0x70b71d6778700015 +10098:09/09 19:07:23.426118 00161914 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d77787a1000d:0x70b71d6778700015 +10105:09/09 19:07:23.426263 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +10106:09/09 19:07:23.426291 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +10107:09/09 19:07:23.426299 00161875 C RPC DND-S conn 0x7f73780418e0 heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:855, seqNum:9, qid:15, gtid:0xadc8d77787a1000d:0x70b71d6778700015 +10108:09/09 19:07:23.426303 00161875 C RPC conn 0x7f73780418e0 ref count:2 +10109:09/09 19:07:23.426358 00161875 C RPC DND-S conn 0x7f73780418e0 send data +10110:09/09 19:07:23.426383 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:9, qid:15, gtid:0xadc8d77787a1000d:0x70b71d6778700015 +10112:09/09 19:07:23.426393 00161875 C RPC conn 0x7f73780418e0 ref count:1 +10285:09/09 19:07:24.604388 00161881 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0x0:0x70b71d6775200005 +10291:09/09 19:07:24.604484 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +10292:09/09 19:07:24.604492 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +10293:09/09 19:07:24.604497 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:116, seqNum:1, qid:4, gtid:0x0:0x70b71d6775200005 +10294:09/09 19:07:24.604502 00161875 C RPC conn 0x7f73780418e0 ref count:2 +10295:09/09 19:07:24.604552 00161875 C RPC DND-S conn 0x7f73780418e0 send data +10296:09/09 19:07:24.604575 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:1, qid:4, gtid:0x0:0x70b71d6775200005 +10298:09/09 19:07:24.604585 00161875 C RPC conn 0x7f73780418e0 ref count:1 +10463:09/09 19:07:24.866345 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +10465:09/09 19:07:24.866385 00161875 C RPC DND-S conn 0x7f73780418e0 vnode-batch-meta received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:90, cost:107us, seqNum:10, qid:0, gtid:0xadc8d7778d40000e:0x70b71d6778d00017 +10466:09/09 19:07:24.866389 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d00017 +10542:09/09 19:07:24.867015 00162315 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d7778d40000e:0x70b71d6778d00017 +10549:09/09 19:07:24.867083 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +10550:09/09 19:07:24.867088 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +10551:09/09 19:07:24.867093 00161875 C RPC DND-S conn 0x7f73780418e0 vnode-batch-meta is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:329, seqNum:10, qid:0, gtid:0xadc8d7778d40000e:0x70b71d6778d00017 +10552:09/09 19:07:24.867097 00161875 C RPC conn 0x7f73780418e0 ref count:2 +10553:09/09 19:07:24.867137 00161875 C RPC DND-S conn 0x7f73780418e0 send data +10554:09/09 19:07:24.867144 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:10, qid:0, gtid:0xadc8d7778d40000e:0x70b71d6778d00017 +10556:09/09 19:07:24.867153 00161875 C RPC conn 0x7f73780418e0 ref count:1 +10601:09/09 19:07:24.869034 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +10603:09/09 19:07:24.869064 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:41, cost:93us, seqNum:11, qid:16, gtid:0x0:0x70b71d6778d00019 +10604:09/09 19:07:24.869067 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0x0:0x70b71d6778d00019 +10626:09/09 19:07:24.869574 00162315 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback +10635:09/09 19:07:24.869602 00162315 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0x0:0x70b71d6778d00019 +10643:09/09 19:07:24.869659 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback +10644:09/09 19:07:24.869661 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:16 +10645:09/09 19:07:24.869664 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ +10648:09/09 19:07:24.869670 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +10649:09/09 19:07:24.869672 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +10650:09/09 19:07:24.869674 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:116, seqNum:11, qid:16, gtid:0x0:0x70b71d6778d00019 +10651:09/09 19:07:24.869676 00161875 C RPC conn 0x7f73780418e0 ref count:2 +10652:09/09 19:07:24.869698 00161875 C RPC DND-S conn 0x7f73780418e0 send data +10653:09/09 19:07:24.869701 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:11, qid:16, gtid:0x0:0x70b71d6778d00019 +10655:09/09 19:07:24.869705 00161875 C RPC conn 0x7f73780418e0 ref count:1 +10656:09/09 19:07:24.869711 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +10658:09/09 19:07:24.869727 00161875 C RPC DND-S conn 0x7f73780418e0 query received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:1312, cost:373us, seqNum:12, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b +10659:09/09 19:07:24.869729 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b +10668:09/09 19:07:24.869752 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback +10677:09/09 19:07:24.869921 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback +10678:09/09 19:07:24.869925 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:18 +10679:09/09 19:07:24.869929 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ +10858:09/09 19:07:24.872444 00162312 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d7778d40000e:0x70b71d6778d0001b +10867:09/09 19:07:24.872486 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +10869:09/09 19:07:24.872493 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +10870:09/09 19:07:24.872496 00161875 C RPC DND-S conn 0x7f73780418e0 query-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:130, seqNum:12, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b +10871:09/09 19:07:24.872498 00161875 C RPC conn 0x7f73780418e0 ref count:2 +10872:09/09 19:07:24.872518 00161875 C RPC DND-S conn 0x7f73780418e0 send data +10873:09/09 19:07:24.872521 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:12, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b +10875:09/09 19:07:24.872525 00161875 C RPC conn 0x7f73780418e0 ref count:1 +10952:09/09 19:07:24.873453 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +10954:09/09 19:07:24.873476 00161875 C RPC DND-S conn 0x7f73780418e0 merge-query received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:595, cost:107us, seqNum:13, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d +10955:09/09 19:07:24.873479 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d +10964:09/09 19:07:24.873500 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback +10972:09/09 19:07:24.873553 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback +10977:09/09 19:07:24.873556 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:20 +10981:09/09 19:07:24.873672 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ +11153:09/09 19:07:24.874866 00163053 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d7778d40000e:0x70b71d6778d0001d +11159:09/09 19:07:24.874914 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +11160:09/09 19:07:24.874926 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +11162:09/09 19:07:24.874930 00161875 C RPC DND-S conn 0x7f73780418e0 merge-query-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:111, seqNum:13, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d +11166:09/09 19:07:24.874933 00161875 C RPC conn 0x7f73780418e0 ref count:2 +11167:09/09 19:07:24.875549 00161875 C RPC DND-S conn 0x7f73780418e0 send data +11168:09/09 19:07:24.875602 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:13, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d +11170:09/09 19:07:24.875646 00161875 C RPC conn 0x7f73780418e0 ref count:1 +11171:09/09 19:07:24.876014 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +11173:09/09 19:07:24.876039 00161875 C RPC DND-S conn 0x7f73780418e0 merge-fetch received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:44, cost:62us, seqNum:14, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001e +11174:09/09 19:07:24.876042 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d0001e +11200:09/09 19:07:24.876181 00162337 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d7778d40000e:0x70b71d6778d0001e +11209:09/09 19:07:24.876215 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +11210:09/09 19:07:24.876217 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +11211:09/09 19:07:24.876219 00161875 C RPC DND-S conn 0x7f73780418e0 merge-fetch-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:1110, seqNum:14, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001e +11212:09/09 19:07:24.876221 00161875 C RPC conn 0x7f73780418e0 ref count:2 +11213:09/09 19:07:24.876246 00161875 C RPC DND-S conn 0x7f73780418e0 send data +11214:09/09 19:07:24.876249 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:14, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001e +11216:09/09 19:07:24.876253 00161875 C RPC conn 0x7f73780418e0 ref count:1 +11217:09/09 19:07:24.876706 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +11219:09/09 19:07:24.876732 00161875 C RPC DND-S conn 0x7f73780418e0 drop-task received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:48, cost:54us, seqNum:15, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001f +11220:09/09 19:07:24.876734 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d0001f +11235:09/09 19:07:24.876834 00162315 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:18 +11255:09/09 19:07:24.877107 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +11257:09/09 19:07:24.877134 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +11259:09/09 19:07:24.877149 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b +11260:09/09 19:07:24.877169 00161875 C RPC conn 0x7f73780418e0 ref count:2 +11263:09/09 19:07:24.877193 00161875 C RPC DND-S conn 0x7f73780418e0 send data +11264:09/09 19:07:24.877294 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b +11266:09/09 19:07:24.877323 00161875 C RPC conn 0x7f73780418e0 ref count:1 +11270:09/09 19:07:24.877340 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +11275:09/09 19:07:24.877458 00161875 C RPC DND-S conn 0x7f73780418e0 drop-task received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:48, cost:717us, seqNum:16, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d00021 +11276:09/09 19:07:24.877461 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d00021 +11342:09/09 19:07:24.877977 00162337 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:20 +11359:09/09 19:07:24.878137 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +11361:09/09 19:07:24.878182 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +11363:09/09 19:07:24.878186 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d +11364:09/09 19:07:24.878189 00161875 C RPC conn 0x7f73780418e0 ref count:2 +11365:09/09 19:07:24.878208 00161875 C RPC DND-S conn 0x7f73780418e0 send data +11366:09/09 19:07:24.878220 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d +11368:09/09 19:07:24.878224 00161875 C RPC conn 0x7f73780418e0 ref count:1 +11944:09/09 19:07:26.247094 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +11947:09/09 19:07:26.247153 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:41, cost:126us, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 +11949:09/09 19:07:26.247163 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0x0:0x70b71d6779200023 +11981:09/09 19:07:26.247510 00162315 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback +11992:09/09 19:07:26.247599 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback +11993:09/09 19:07:26.247602 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:22 +11994:09/09 19:07:26.247605 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ +11995:09/09 19:07:26.247578 00162315 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:16 +12007:09/09 19:07:26.247821 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +12011:09/09 19:07:26.247956 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +12013:09/09 19:07:26.247973 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:16, gtid:0x0:0x70b71d6778d00019 +12020:09/09 19:07:26.248038 00162315 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0x0:0x70b71d6779200023 +12026:09/09 19:07:26.247975 00161875 C RPC conn 0x7f73780418e0 ref count:2 +12031:09/09 19:07:26.248166 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +12033:09/09 19:07:26.248206 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +12034:09/09 19:07:26.248217 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:116, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 +12037:09/09 19:07:26.248248 00161875 C RPC conn 0x7f73780418e0 ref count:3 +12043:09/09 19:07:26.248296 00161875 C RPC DND-S conn 0x7f73780418e0 send data +12044:09/09 19:07:26.248341 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:16, gtid:0x0:0x70b71d6778d00019 +12049:09/09 19:07:26.248433 00161875 C RPC conn 0x7f73780418e0 ref count:2 +12050:09/09 19:07:26.248441 00161875 C RPC DND-S conn 0x7f73780418e0 send data +12054:09/09 19:07:26.248503 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 +12074:09/09 19:07:26.248787 00161875 C RPC conn 0x7f73780418e0 ref count:1 +12076:09/09 19:07:26.248887 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +12082:09/09 19:07:26.248920 00161875 C RPC DND-S conn 0x7f73780418e0 query received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:1312, cost:1830us, seqNum:18, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 +12090:09/09 19:07:26.249021 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d6779200025 +12109:09/09 19:07:26.249567 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback +12127:09/09 19:07:26.249617 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback +12130:09/09 19:07:26.249623 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:24 +12139:09/09 19:07:26.249633 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ +12302:09/09 19:07:26.251246 00162269 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d77792a60010:0x70b71d6779200025 +12317:09/09 19:07:26.251495 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +12318:09/09 19:07:26.251597 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +12319:09/09 19:07:26.251602 00161875 C RPC DND-S conn 0x7f73780418e0 query-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:130, seqNum:18, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 +12320:09/09 19:07:26.251604 00161875 C RPC conn 0x7f73780418e0 ref count:2 +12321:09/09 19:07:26.251611 00161875 C RPC DND-S conn 0x7f73780418e0 send data +12322:09/09 19:07:26.251613 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:18, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 +12324:09/09 19:07:26.251616 00161875 C RPC conn 0x7f73780418e0 ref count:1 +12327:09/09 19:07:26.290976 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +12329:09/09 19:07:26.291023 00161875 C RPC DND-S conn 0x7f73780418e0 merge-query received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:595, cost:96us, seqNum:19, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 +12330:09/09 19:07:26.291026 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d6779200027 +12339:09/09 19:07:26.291064 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback +12347:09/09 19:07:26.291142 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback +12348:09/09 19:07:26.291145 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:26 +12351:09/09 19:07:26.291148 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ +12528:09/09 19:07:26.292905 00162273 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d77792a60010:0x70b71d6779200027 +12532:09/09 19:07:26.292977 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +12536:09/09 19:07:26.292980 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +12538:09/09 19:07:26.293019 00161875 C RPC DND-S conn 0x7f73780418e0 merge-query-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:111, seqNum:19, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 +12541:09/09 19:07:26.293025 00161875 C RPC conn 0x7f73780418e0 ref count:2 +12542:09/09 19:07:26.293054 00161875 C RPC DND-S conn 0x7f73780418e0 send data +12543:09/09 19:07:26.293068 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:19, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 +12545:09/09 19:07:26.293073 00161875 C RPC conn 0x7f73780418e0 ref count:1 +12546:09/09 19:07:26.293505 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +12548:09/09 19:07:26.293524 00161875 C RPC DND-S conn 0x7f73780418e0 merge-fetch received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:44, cost:65us, seqNum:20, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200028 +12549:09/09 19:07:26.293526 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d6779200028 +12575:09/09 19:07:26.293624 00162337 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d77792a60010:0x70b71d6779200028 +12579:09/09 19:07:26.293691 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +12581:09/09 19:07:26.293694 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +12582:09/09 19:07:26.293711 00161875 C RPC DND-S conn 0x7f73780418e0 merge-fetch-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:1110, seqNum:20, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200028 +12583:09/09 19:07:26.293733 00161875 C RPC conn 0x7f73780418e0 ref count:2 +12588:09/09 19:07:26.293847 00161875 C RPC DND-S conn 0x7f73780418e0 send data +12589:09/09 19:07:26.293861 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:20, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200028 +12591:09/09 19:07:26.293866 00161875 C RPC conn 0x7f73780418e0 ref count:1 +12602:09/09 19:07:26.294162 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +12609:09/09 19:07:26.294319 00161875 C RPC DND-S conn 0x7f73780418e0 drop-task received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:48, cost:204us, seqNum:21, qid:26, gtid:0xadc8d77792a60010:0x70b71d677920002a +12610:09/09 19:07:26.294508 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d677920002a +12663:09/09 19:07:26.295131 00162337 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:26 +12680:09/09 19:07:26.295340 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +12682:09/09 19:07:26.295381 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +12684:09/09 19:07:26.295419 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 +12685:09/09 19:07:26.295431 00161875 C RPC conn 0x7f73780418e0 ref count:2 +12686:09/09 19:07:26.295510 00161875 C RPC DND-S conn 0x7f73780418e0 send data +12687:09/09 19:07:26.295527 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 +12689:09/09 19:07:26.295532 00161875 C RPC conn 0x7f73780418e0 ref count:1 +12690:09/09 19:07:26.295540 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf +12692:09/09 19:07:26.295557 00161875 C RPC DND-S conn 0x7f73780418e0 drop-task received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:48, cost:1397us, seqNum:22, qid:24, gtid:0xadc8d77792a60010:0x70b71d677920002b +12693:09/09 19:07:26.295559 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d677920002b +12708:09/09 19:07:26.295660 00162315 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:24 +12713:09/09 19:07:26.295705 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +12716:09/09 19:07:26.295713 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +12718:09/09 19:07:26.295749 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 +12719:09/09 19:07:26.295752 00161875 C RPC conn 0x7f73780418e0 ref count:2 +12721:09/09 19:07:26.295774 00161875 C RPC DND-S conn 0x7f73780418e0 send data +12722:09/09 19:07:26.295795 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 +12724:09/09 19:07:26.295800 00161875 C RPC conn 0x7f73780418e0 ref count:1 +12939:09/09 19:07:27.279390 00161881 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0x0:0x70b71d6779200023 +12943:09/09 19:07:27.279480 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) +12944:09/09 19:07:27.279486 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send +12945:09/09 19:07:27.279491 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:116, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 +12946:09/09 19:07:27.279494 00161875 C RPC conn 0x7f73780418e0 ref count:2 +12947:09/09 19:07:27.279530 00161875 C RPC DND-S conn 0x7f73780418e0 send data +12948:09/09 19:07:27.279560 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 +12950:09/09 19:07:27.279585 00161875 C RPC conn 0x7f73780418e0 ref count:1 +13094:09/09 19:07:27.747059 00161875 C RPC DND-S conn 0x7f73780418e0 read error:EOF +13095:09/09 19:07:27.747080 00161875 C RPC conn 0x7f73780418e0 to be destroyed +13098:09/09 19:07:27.747108 00161875 C RPC DND-S conn 0x7f73780418e0 destroy diff --git a/qid b/qid new file mode 100644 index 0000000000..d8a8431ea0 --- /dev/null +++ b/qid @@ -0,0 +1,216 @@ +11802:09/09 19:41:59.586660 00211996 C RPC DND-S conn 0x7fa218014af0 query received from 127.0.0.1:37174, local info:127.0.0.1:6100, len:1312, cost:589us, seqNum:16, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 +11803:09/09 19:41:59.586682 00211996 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 prerocessQuery start, handle:0x7fa218021f60, SQL:select * from test.sp; +11804:09/09 19:41:59.586684 00211994 C RPC DND-S conn 0x7fa210002100 query received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:1312, cost:642us, seqNum:15, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 +11806:09/09 19:41:59.586698 00211994 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 prerocessQuery start, handle:0x7fa210010ec0, SQL:select * from test.sp; +11807:09/09 19:41:59.586700 00211996 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status added, newStatus:INIT +11808:09/09 19:41:59.586713 00211996 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 prerocessQuery end, handle:0x7fa218021f60, code:0 +11810:09/09 19:41:59.586728 00211994 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status added, newStatus:INIT +11811:09/09 19:41:59.586734 00211994 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 prerocessQuery end, handle:0x7fa210010ec0, code:0 +11818:09/09 19:41:59.586785 00212137 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processQuery start, node:0x7fa24d7e8f50, type:query, compress:0, handle:0x7fa210010ec0, SQL:select * from test.sp; +11819:09/09 19:41:59.586795 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to handle event at phase PRE_QUERY +11820:09/09 19:41:59.586802 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status updated from INIT to EXECUTING +11821:09/09 19:41:59.586805 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 end to handle event at phase PRE_QUERY, code:success +11822:09/09 19:41:59.586816 00212138 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processQuery start, node:0x7fa24cfe7f50, type:query, compress:0, handle:0x7fa218021f60, SQL:select * from test.sp; +11823:09/09 19:41:59.586831 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to handle event at phase PRE_QUERY +11824:09/09 19:41:59.586837 00212137 C QRY start to create task, TID:0xa QID:0x2e20039735a00008, vgId:2 +11825:09/09 19:41:59.586840 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status updated from INIT to EXECUTING +11826:09/09 19:41:59.586845 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 end to handle event at phase PRE_QUERY, code:success +11827:09/09 19:41:59.586878 00212137 C QRY extract queried table list completed, 1 tables, elapsed time:0.00 ms TID:0xa QID:0x2e20039735a00008 +11828:09/09 19:41:59.586887 00212137 C QRY generate group id map completed, elapsed time:0.01 ms TID:0xa QID:0x2e20039735a00008 +11829:09/09 19:41:59.586891 00212138 C QRY start to create task, TID:0xb QID:0x2e20039735a00008, vgId:3 +11830:09/09 19:41:59.586919 00212137 C QRY subplan task create completed, TID:0xa QID:0x2e20039735a00008 +11831:09/09 19:41:59.586925 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to execTask, loopIdx:0 +11832:09/09 19:41:59.586928 00212137 C QRY TID:0xa QID:0x2e20039735a00008 execTask is launched +11833:09/09 19:41:59.586943 00212138 C QRY extract queried table list completed, 0 tables, elapsed time:0.00 ms TID:0xb QID:0x2e20039735a00008 +11834:09/09 19:41:59.586950 00212137 C TSD 0x7fa16001f930 create 1 tables scan-info, size:0.38 Kb, elapsed time:0.00 ms, TID:0xa QID:0x2e20039735a00008 +11835:09/09 19:41:59.586955 00212137 C TSD 0x7fa16001f930 total numOfTable:1, window:1410522119587 - 9223372036854775807, verRange:0 - 46 in this query TID:0xa QID:0x2e20039735a00008 +11836:09/09 19:41:59.586967 00212137 C TSD init fileset iterator, total files:1 TID:0xa QID:0x2e20039735a00008 +11837:09/09 19:41:59.586951 00212138 C QRY no table qualified for query, TID:0xb QID:0x2e20039735a00008lx +11838:09/09 19:41:59.586972 00212137 C TSD 0x7fa16001f930 file found fid:1997 for qrange:1410522119587-9223372036854775807, TID:0xa QID:0x2e20039735a00008 +11839:09/09 19:41:59.586979 00212137 C TSD load block of 1 tables completed, blocks:0 in 0 tables, stt-files:1, block-info-size:0.00 Kb, elapsed time:0.00 ms TID:0xa QID:0x2e20039735a00008 +11840:09/09 19:41:59.586983 00212137 C TSD reader: 0x7fa16001f930 resumed uid 0, numOfTable:1, in this query TID:0xa QID:0x2e20039735a00008 +11841:09/09 19:41:59.586986 00212137 C TSD seq load data blocks from stt files TID:0xa QID:0x2e20039735a00008 +11842:09/09 19:41:59.586989 00212137 C TSD init stt block reader, window:1410522119587-9223372036854775807, uid:8502546947039559767, TID:0xa QID:0x2e20039735a00008 +11843:09/09 19:41:59.587009 00212138 C QRY subplan task create completed, TID:0xb QID:0x2e20039735a00008 +11844:09/09 19:41:59.587018 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to execTask, loopIdx:0 +11845:09/09 19:41:59.587022 00212138 C QRY TID:0xb QID:0x2e20039735a00008 execTask is launched +11846:09/09 19:41:59.587040 00212137 C TSD TID:0xa QID:0x2e20039735a00008 load 1 statis blocks into buf, elapsed time:0.01ms +11847:09/09 19:41:59.587045 00212137 C TSD load the stt file blk info completed, elapsed time:0.02ms, TID:0xa QID:0x2e20039735a00008 +11848:09/09 19:41:59.587050 00212138 C TSD 0x7fa16401f900 create 0 tables scan-info, size:0.00 Kb, elapsed time:0.00 ms, TID:0xb QID:0x2e20039735a00008 +11849:09/09 19:41:59.587056 00212138 C TSD 0x7fa16401f900 total numOfTable:0, window:1410522119588 - 9223372036854775807, verRange:0 - 4 in this query TID:0xb QID:0x2e20039735a00008 +11850:09/09 19:41:59.587061 00212138 C TSD reader: 0x7fa16401f900 resumed uid 0, numOfTable:0, in this query TID:0xb QID:0x2e20039735a00008 +11851:09/09 19:41:59.587063 00212137 C TSD read stt block, total load:1, trigger by uid:8502546947039559767, stt-fileVer:1, last block index:0, entry:0, rows:42, uidRange:8502546947039559767-8502546947039559767 tsRange:1725878896277-1725878917534 0x7fa1600223d0, elapsed time:0.01 ms, TID:0xa QID:0x2e20039735a00008 +11853:09/09 19:41:59.587067 00212137 C TSD last block index list:0, -1, rowIndex:-1 TID:0xa QID:0x2e20039735a00008 +11854:09/09 19:41:59.587107 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11856:09/09 19:41:59.587118 00212138 C QRY TID:0xb QID:0x2e20039735a00008 task suspended, 0 rows in 0 blocks returned, total:0 rows, in sinkNode:0, elapsed:0.00 ms +11857:09/09 19:41:59.587124 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 qExecTask end with empty res, useconds:0 +11858:09/09 19:41:59.587131 00212137 C TSD 0x7fa16001f930 uid:8502546947039559767, no data in mem, TID:0xa QID:0x2e20039735a00008 +11859:09/09 19:41:59.587136 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to handle event at phase POST_QUERY +11860:09/09 19:41:59.587139 00212137 C TSD 0x7fa16001f930 uid:8502546947039559767, no data in imem, TID:0xa QID:0x2e20039735a00008 +11861:09/09 19:41:59.587166 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status updated from EXECUTING to PARTIAL_SUCCEED +11862:09/09 19:41:59.587172 00212137 C TSD init stt block reader completed, elapsed time:183us TID:0xa QID:0x2e20039735a00008 +11863:09/09 19:41:59.587178 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11864:09/09 19:41:59.587179 00212138 C RPC conn 0x7fa218014af0 start to send resp (1/2), gtid:0x2e20039735a00008:0x26f31d6973500026 +11865:09/09 19:41:59.587198 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11866:09/09 19:41:59.587203 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11867:09/09 19:41:59.587206 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11868:09/09 19:41:59.587207 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 query msg rsped, handle:0x7fa218021f60, code:0 - success +11869:09/09 19:41:59.587215 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 end to handle event at phase POST_QUERY, code:0 - success +11870:09/09 19:41:59.587220 00212138 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processQuery end, node:0x7fa24cfe7f50, code:0 +11871:09/09 19:41:59.587223 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11872:09/09 19:41:59.587228 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11873:09/09 19:41:59.587232 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11876:09/09 19:41:59.587308 00211996 C RPC DND-S conn 0x7fa218014af0 query-rsp is sent to 127.0.0.1:37174, local info:127.0.0.1:6100, len:130, seqNum:16, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 +11878:09/09 19:41:59.587326 00211996 C RPC DND-S conn 0x7fa218014af0 msg already send out, seqNum:16, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 +11879:09/09 19:41:59.587252 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11880:09/09 19:41:59.587507 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11881:09/09 19:41:59.587545 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11882:09/09 19:41:59.587554 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11883:09/09 19:41:59.587580 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11884:09/09 19:41:59.587608 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11885:09/09 19:41:59.587635 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11886:09/09 19:41:59.587663 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11887:09/09 19:41:59.587690 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11888:09/09 19:41:59.587719 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11889:09/09 19:41:59.587745 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11890:09/09 19:41:59.587781 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11891:09/09 19:41:59.587828 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11892:09/09 19:41:59.587856 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11893:09/09 19:41:59.587883 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11894:09/09 19:41:59.587910 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11895:09/09 19:41:59.587937 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11896:09/09 19:41:59.587964 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11897:09/09 19:41:59.587990 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11898:09/09 19:41:59.588034 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11899:09/09 19:41:59.588061 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11900:09/09 19:41:59.588087 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11901:09/09 19:41:59.588114 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11902:09/09 19:41:59.588139 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11903:09/09 19:41:59.588168 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11904:09/09 19:41:59.588176 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11905:09/09 19:41:59.588202 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11906:09/09 19:41:59.588228 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11907:09/09 19:41:59.588254 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11908:09/09 19:41:59.588298 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11909:09/09 19:41:59.588325 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11910:09/09 19:41:59.588351 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11911:09/09 19:41:59.588377 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11912:09/09 19:41:59.588385 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11913:09/09 19:41:59.588409 00212137 C TSD no more last block qualified, uid:8502546947039559767, stt-file block:0, TID:0xa QID:0x2e20039735a00008 +11914:09/09 19:41:59.588415 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 +11915:09/09 19:41:59.588444 00212137 C TSD 0x7fa16001f930 uid:8502546947039559767, composed data block created, brange:1725878896277-1725878917534 rows:42, elapsed time:1.27 ms TID:0xa QID:0x2e20039735a00008 +11916:09/09 19:41:59.588470 00212137 C QRY retrieve table meta from cache:1, hit:0 miss:1, TID:0xa QID:0x2e20039735a00008 +11917:09/09 19:41:59.588498 00212137 C TSD seq load data blocks from stt files TID:0xa QID:0x2e20039735a00008 +11918:09/09 19:41:59.588503 00212137 C TSD seq load data blocks from cache, TID:0xa QID:0x2e20039735a00008 +11921:09/09 19:41:59.588518 00212137 C QRY TID:0xa QID:0x2e20039735a00008 task suspended, 42 rows in 1 blocks returned, total:42 rows, in sinkNode:0, elapsed:1.59 ms +11922:09/09 19:41:59.588535 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 data put into sink, rows:42, continueExecTask:1 +11923:09/09 19:41:59.588539 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 qExecTask done, useconds:1587 +11924:09/09 19:41:59.588542 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to handle event at phase POST_QUERY +11925:09/09 19:41:59.588549 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status updated from EXECUTING to PARTIAL_SUCCEED +11926:09/09 19:41:59.588558 00212137 C RPC conn 0x7fa210002100 start to send resp (1/2), gtid:0x2e20039735a00008:0x26f31d6973500025 +11927:09/09 19:41:59.588587 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 query msg rsped, handle:0x7fa210010ec0, code:0 - success +11928:09/09 19:41:59.588594 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 end to handle event at phase POST_QUERY, code:0 - success +11930:09/09 19:41:59.588600 00212137 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processQuery end, node:0x7fa24d7e8f50, code:0 +11932:09/09 19:41:59.588608 00211994 C RPC DND-S conn 0x7fa210002100 query-rsp is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:130, seqNum:15, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 +11934:09/09 19:41:59.588616 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:15, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 +11935:09/09 19:41:59.631192 00211994 C RPC DND-S conn 0x7fa210002100 merge-query received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:595, cost:80us, seqNum:16, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 +11936:09/09 19:41:59.631228 00211994 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 prerocessQuery start, handle:0x7fa210010ec0, SQL:select * from test.sp; +11938:09/09 19:41:59.631255 00211994 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status added, newStatus:INIT +11939:09/09 19:41:59.631260 00211994 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 prerocessQuery end, handle:0x7fa210010ec0, code:0 +11943:09/09 19:41:59.631349 00212139 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processQuery start, node:0x7fa24c7e6f50, type:merge-query, compress:0, handle:0x7fa210010ec0, SQL:select * from test.sp; +11944:09/09 19:41:59.631367 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to handle event at phase PRE_QUERY +11945:09/09 19:41:59.631378 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status updated from INIT to EXECUTING +11946:09/09 19:41:59.631382 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 end to handle event at phase PRE_QUERY, code:success +11947:09/09 19:41:59.631410 00212139 C QRY start to create task, TID:0x9 QID:0x2e20039735a00008, vgId:2 +11948:09/09 19:41:59.631435 00212139 C QRY subplan task create completed, TID:0x9 QID:0x2e20039735a00008 +11949:09/09 19:41:59.631439 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to execTask, loopIdx:0 +11950:09/09 19:41:59.631443 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 execTask is launched +11951:09/09 19:41:59.631450 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 build fetch msg and send to vgId:3, ep:localhost, taskId:0xb, execId:0, 0x7fa158002f60, 0/2 +11955:09/09 19:41:59.631501 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 build fetch msg and send to vgId:2, ep:localhost, taskId:0xa, execId:0, 0x7fa158002f60, 1/2 +11960:09/09 19:41:59.631527 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 send all fetch requests to 2 sources completed, elapsed:0.08ms +11961:09/09 19:41:59.631554 00212139 C QRY prepare wait for ready, 0x7fa158002f60, TID:0x9 QID:0x2e20039735a00008 +11974:09/09 19:41:59.631693 00212158 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processFetch start, node:0x7fa288001640, handle:0x7fa210021de0 +11975:09/09 19:41:59.631702 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to handle event at phase PRE_FETCH +11976:09/09 19:41:59.631709 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 end to handle event at phase PRE_FETCH, code:success +11977:09/09 19:41:59.631714 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 no more data in sink and query end, fetched blocks 0 rows 0 +11978:09/09 19:41:59.631721 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status updated from PARTIAL_SUCCEED to SUCCEED +11979:09/09 19:41:59.631725 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to handle event at phase POST_FETCH +11980:09/09 19:41:59.631728 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 end to handle event at phase POST_FETCH, code:0 - success +11982:09/09 19:41:59.631756 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 fetch rsp send, msgType:fetch-rsp, handle:0x7fa210021de0, code:0 - success, dataLen:0 +11983:09/09 19:41:59.631761 00212158 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processFetch end, node:0x7fa288001640, code:0 +11990:09/09 19:41:59.631932 00211999 C QRY TID:0x9 QID:0x2e20039735a00008 fetch rsp received, index:0, blocks:0, rows:0, 0x7fa158002f60 +11993:09/09 19:41:59.631972 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 vgId:3, taskId:0xb execId:0 index:0 completed, rowsOfSource:0, totalRows:0, try next 1/2 +11994:09/09 19:41:59.631993 00212139 C QRY prepare wait for ready, 0x7fa158002f60, TID:0x9 QID:0x2e20039735a00008 +11995:09/09 19:41:59.632005 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processFetch start, node:0x7fa290001630, handle:0x7fa210021de0 +11996:09/09 19:41:59.632013 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to handle event at phase PRE_FETCH +11997:09/09 19:41:59.632018 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 end to handle event at phase PRE_FETCH, code:success +11999:09/09 19:41:59.632025 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 there are data in sink, dataLength:746 +12000:09/09 19:41:59.632029 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task all data fetched and done, fetched blocks 1 rows 42 +12001:09/09 19:41:59.632033 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status updated from PARTIAL_SUCCEED to SUCCEED +12002:09/09 19:41:59.632036 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to handle event at phase POST_FETCH +12003:09/09 19:41:59.632038 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 end to handle event at phase POST_FETCH, code:0 - success +12005:09/09 19:41:59.632063 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 fetch rsp send, msgType:fetch-rsp, handle:0x7fa210021de0, code:0 - success, dataLen:754 +12006:09/09 19:41:59.632068 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processFetch end, node:0x7fa290001630, code:0 +12013:09/09 19:41:59.632150 00211999 C QRY TID:0x9 QID:0x2e20039735a00008 fetch rsp received, index:1, blocks:1, rows:42, 0x7fa158002f60 +12015:09/09 19:41:59.632191 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 fetch msg rsp from vgId:2, taskId:0xa execId:0 index:1 completed, blocks:1, numOfRows:42, rowsOfSource:42, totalRows:42, total:0.74 Kb, try next 2/2 +12016:09/09 19:41:59.632206 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 all 2 sources are exhausted, total rows: 42, 0.74 Kb, elapsed:0.69 ms +12017:09/09 19:41:59.632212 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 task suspended, 42 rows in 1 blocks returned, total:42 rows, in sinkNode:0, elapsed:0.77 ms +12018:09/09 19:41:59.632219 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 data put into sink, rows:42, continueExecTask:1 +12019:09/09 19:41:59.632222 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 qExecTask done, useconds:766 +12020:09/09 19:41:59.632226 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to handle event at phase POST_QUERY +12021:09/09 19:41:59.632238 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status updated from EXECUTING to PARTIAL_SUCCEED +12022:09/09 19:41:59.632246 00212139 C RPC conn 0x7fa210002100 start to send resp (1/2), gtid:0x2e20039735a00008:0x26f31d6973500027 +12023:09/09 19:41:59.632271 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 query msg rsped, handle:0x7fa210010ec0, code:0 - success +12024:09/09 19:41:59.632277 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 end to handle event at phase POST_QUERY, code:0 - success +12025:09/09 19:41:59.632282 00212139 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processQuery end, node:0x7fa24c7e6f50, code:0 +12028:09/09 19:41:59.632295 00211994 C RPC DND-S conn 0x7fa210002100 merge-query-rsp is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:111, seqNum:16, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 +12030:09/09 19:41:59.632333 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:16, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 +12031:09/09 19:41:59.632825 00211994 C RPC DND-S conn 0x7fa210002100 merge-fetch received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:44, cost:54us, seqNum:17, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500028 +12032:09/09 19:41:59.632870 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processFetch start, node:0x7fa290001630, handle:0x7fa210010ec0 +12033:09/09 19:41:59.632878 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to handle event at phase PRE_FETCH +12034:09/09 19:41:59.632882 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 end to handle event at phase PRE_FETCH, code:success +12036:09/09 19:41:59.632887 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 there are data in sink, dataLength:746 +12037:09/09 19:41:59.632890 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task all data fetched and done, fetched blocks 1 rows 42 +12038:09/09 19:41:59.632894 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status updated from PARTIAL_SUCCEED to SUCCEED +12039:09/09 19:41:59.632896 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to handle event at phase POST_FETCH +12040:09/09 19:41:59.632899 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 end to handle event at phase POST_FETCH, code:0 - success +12041:09/09 19:41:59.632902 00212159 C RPC conn 0x7fa210002100 start to send resp (1/2), gtid:0x2e20039735a00008:0x26f31d6973500028 +12042:09/09 19:41:59.632921 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 fetch rsp send, msgType:merge-fetch-rsp, handle:0x7fa210010ec0, code:0 - success, dataLen:754 +12043:09/09 19:41:59.632925 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processFetch end, node:0x7fa290001630, code:0 +12046:09/09 19:41:59.632944 00211994 C RPC DND-S conn 0x7fa210002100 merge-fetch-rsp is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:1110, seqNum:17, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500028 +12048:09/09 19:41:59.632984 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:17, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500028 +12049:09/09 19:41:59.633734 00211994 C RPC DND-S conn 0x7fa210002100 drop-task received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:48, cost:49us, seqNum:18, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500029 +12050:09/09 19:41:59.633780 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processDrop start, node:0x7fa290001630, handle:0x7fa210010ec0 +12051:09/09 19:41:59.633805 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status dropped +12053:09/09 19:41:59.633842 00211996 C RPC DND-S conn 0x7fa218014af0 drop-task received from 127.0.0.1:37174, local info:127.0.0.1:6100, len:48, cost:43us, seqNum:17, qid:22, gtid:0x2e20039735a00008:0x26f31d697350002b +12054:09/09 19:41:59.633842 00212159 C QRY TID:0x9 QID:0x2e20039735a00008 execTask completed, numOfRows:42 +12055:09/09 19:41:59.633853 00212159 C QRY TID:0x9 QID:0x2e20039735a00008 :cost summary: idle in queue:0.03 ms, elapsed time:0.77 ms +12057:09/09 19:41:59.633878 00212158 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processDrop start, node:0x7fa288001640, handle:0x7fa218021f60 +12058:09/09 19:41:59.633892 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status dropped +12059:09/09 19:41:59.633859 00212159 C QRY TID:0x9 QID:0x2e20039735a00008 execTask is freed +12063:09/09 19:41:59.633914 00211994 C RPC DND-S conn 0x7fa210002100 task-release is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:91, seqNum:0, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 +12065:09/09 19:41:59.633926 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task ctx dropped +12066:09/09 19:41:59.633928 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task is dropped +12067:09/09 19:41:59.633926 00212158 C QRY TID:0xb QID:0x2e20039735a00008 execTask completed, numOfRows:0 +12068:09/09 19:41:59.633932 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processDrop end, node:0x7fa290001630, code:0 +12069:09/09 19:41:59.633935 00212158 C QRY TID:0xb QID:0x2e20039735a00008 :cost summary: idle:0.12 ms, elapsed time:0.00 ms, extract tableList:0.00 ms, createGroupIdMap:0.00 ms, total blocks:0, load block SMA:0, load data block:0, total rows:0, check rows:0 +12070:09/09 19:41:59.633942 00212158 C QRY TID:0xb QID:0x2e20039735a00008 execTask is freed +12073:09/09 19:41:59.633961 00211996 C RPC DND-S conn 0x7fa218014af0 task-release is sent to 127.0.0.1:37174, local info:127.0.0.1:6100, len:91, seqNum:0, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 +12074:09/09 19:41:59.633961 00212158 C TSD 0x7fa16401f900 :io-cost summary: head-file:0, head-file time:0.00 ms, SMA:0 SMA-time:0.00 ms, fileBlocks:0, fileBlocks-load-time:0.00 ms, build in-memory-block-time:0.00 ms, sttBlocks:0, sttBlocks-time:0.00 ms, sttStatisBlock:0, stt-statis-Block-time:0.00 ms, composed-blocks:0, composed-blocks-time:0.00ms, STableBlockScanInfo size:0.00 Kb, createTime:0.00 ms,createSkylineIterTime:0.00 ms, initSttBlockReader:0.00ms, TID:0xb QID:0x2e20039735a00008 +12076:09/09 19:41:59.633976 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:0, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 +12079:09/09 19:41:59.633989 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task ctx dropped +12080:09/09 19:41:59.633991 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task is dropped +12081:09/09 19:41:59.633991 00211994 C RPC DND-S conn 0x7fa210002100 drop-task received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:48, cost:257us, seqNum:19, qid:21, gtid:0x2e20039735a00008:0x26f31d697350002a +12083:09/09 19:41:59.633995 00212158 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processDrop end, node:0x7fa288001640, code:0 +12084:09/09 19:41:59.634004 00211996 C RPC DND-S conn 0x7fa218014af0 msg already send out, seqNum:0, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 +12085:09/09 19:41:59.634046 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processDrop start, node:0x7fa290001630, handle:0x7fa210010ec0 +12086:09/09 19:41:59.634059 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status dropped +12088:09/09 19:41:59.634091 00212159 C QRY TID:0xa QID:0x2e20039735a00008 execTask completed, numOfRows:42 +12089:09/09 19:41:59.634097 00212159 C QRY TID:0xa QID:0x2e20039735a00008 :cost summary: idle:0.09 ms, elapsed time:1.59 ms, extract tableList:0.00 ms, createGroupIdMap:0.01 ms, total blocks:1, load block SMA:0, load data block:1, total rows:42, check rows:42 +12090:09/09 19:41:59.634105 00212159 C QRY TID:0xa QID:0x2e20039735a00008 execTask is freed +12093:09/09 19:41:59.634123 00211994 C RPC DND-S conn 0x7fa210002100 task-release is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:91, seqNum:0, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 +12094:09/09 19:41:59.634143 00212159 C TSD 0x7fa16001f930 :io-cost summary: head-file:0, head-file time:0.00 ms, SMA:0 SMA-time:0.00 ms, fileBlocks:1, fileBlocks-load-time:0.00 ms, build in-memory-block-time:0.00 ms, sttBlocks:1, sttBlocks-time:0.01 ms, sttStatisBlock:1, stt-statis-Block-time:0.01 ms, composed-blocks:1, composed-blocks-time:1.27ms, STableBlockScanInfo size:0.38 Kb, createTime:0.00 ms,createSkylineIterTime:0.00 ms, initSttBlockReader:0.18ms, TID:0xa QID:0x2e20039735a00008 +12096:09/09 19:41:59.634157 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:0, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 +12099:09/09 19:41:59.634179 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task ctx dropped +12100:09/09 19:41:59.634181 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task is dropped +12101:09/09 19:41:59.634184 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processDrop end, node:0x7fa290001630, code:0 diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3c74fbd168..25ac74d9c0 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1160,6 +1160,9 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { if (handle->data == NULL) { return; } + int32_t fd; + uv_fileno((uv_handle_t*)handle, &fd); + setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int)); SCliConn* conn = handle->data; SConnBuffer* pBuf = &conn->readBuf; @@ -3630,13 +3633,13 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } code = transHeapGet(pHeap, &pConn); - if (pConn && taosHashGetSize(pConn->pQTable) > 0) { - tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); - return NULL; - } /*else { - // tDebug("failed to get conn from heap cache for key:%s", key); - // return NULL; - }*/ + // if (pConn && taosHashGetSize(pConn->pQTable) > 0) { + // tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, + // pConn->reqRefCnt); return NULL; + // } /*else { + // // tDebug("failed to get conn from heap cache for key:%s", key); + // // return NULL; + // }*/ if (code != 0) { tDebug("failed to get conn from heap cache for key:%s", key); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 2b05ad1a65..53e9c0f9b1 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -566,6 +566,9 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { return; } STrans* pInst = conn->pInst; + int32_t fd = 0; + uv_fileno((uv_handle_t*)cli, &fd); + setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int)); SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { diff --git a/sql0 b/sql0 new file mode 100644 index 0000000000..02a6f5d7fb --- /dev/null +++ b/sql0 @@ -0,0 +1,140 @@ +974:09/09 18:52:59.433846 00166866 C TSC 0x6 new Request from connObj:0x2, current:1, app current:1, total:5, reqId:0x987bae6a58a90008 975:09/09 18:52:59.433871 00166866 C TSC 0x6 SQL: select * from test.sp;, reqId:0x987bae6a58a90008 +977:09/09 18:52:59.433972 00166866 C QRY QID:0x987bae6a58a90008 the 0th task type [get db vgroup] initialized, dbFName:1.test +978:09/09 18:52:59.433978 00166866 C QRY QID:0x987bae6a58a90008 the 1th task type [bget table meta] initialized, dbNum:1, tbNum:1 +979:09/09 18:52:59.433982 00166866 C QRY QID:0x987bae6a58a90008 the 2th task type [bget table hash] initialized, dbNum:1, tbNum:1 +980:09/09 18:52:59.433986 00166866 C QRY QID:0x987bae6a58a90008 the 3th task type [get user] initialized, user:root +981:09/09 18:52:59.433991 00166866 C QRY QID:0x987bae6a58a90008, jobId: 0x5 initialized, task num 5, forceUpdate 0, elapsed time:0.03 ms +982:09/09 18:52:59.434002 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [0th] task +985:09/09 18:52:59.434031 00166866 C QRY QID:0x987bae6a58a90008 task 0 end with res success +986:09/09 18:52:59.434036 00166866 C QRY QID:0x987bae6a58a90008 task done: 1, total: 5 +987:09/09 18:52:59.434039 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [1th] task +990:09/09 18:52:59.434053 00166866 C QRY QID:0x987bae6a58a90008 task 1 end with res success +991:09/09 18:52:59.434056 00166866 C QRY QID:0x987bae6a58a90008 task done: 2, total: 5 +992:09/09 18:52:59.434059 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [2th] task +995:09/09 18:52:59.434072 00166866 C QRY QID:0x987bae6a58a90008 task 2 end with res success +996:09/09 18:52:59.434075 00166866 C QRY QID:0x987bae6a58a90008 task done: 3, total: 5 +997:09/09 18:52:59.434078 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [3th] task +1000:09/09 18:52:59.434090 00166866 C QRY QID:0x987bae6a58a90008 task 3 end with res success +1001:09/09 18:52:59.434104 00166866 C QRY QID:0x987bae6a58a90008 task done: 4, total: 5 +1002:09/09 18:52:59.434108 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [4th] task +1003:09/09 18:52:59.434114 00166866 C QRY QID:0x987bae6a58a90008 task 4 end with res success +1004:09/09 18:52:59.434170 00166842 C QRY QID:0x987bae6a58a90008 ctg start to call user cb with rsp success +1005:09/09 18:52:59.434187 00166842 C QRY 0x6 start to semantic analysis, reqId:0x987bae6a58a90008 +1006:09/09 18:52:59.434337 00166842 C TSC 0x987bae6a58a90008 vnode policy, use vnode list, num:2 +1008:09/09 18:52:59.434346 00166842 C QRY QID:0x987bae6a58a90008 set job levelIdx to 1 +1009:09/09 18:52:59.434352 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 task initialized, max times 6:6 +1010:09/09 18:52:59.434355 00166842 C QRY QID:0x987bae6a58a90008 level 0 initialized, taskNum:1 +1011:09/09 18:52:59.434358 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 task initialized, max times 6:12 +1012:09/09 18:52:59.434360 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 task initialized, max times 6:12 +1013:09/09 18:52:59.434361 00166842 C QRY QID:0x987bae6a58a90008 level 1 initialized, taskNum:2 +1014:09/09 18:52:59.434363 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 children info, the 0 child TID 0x7 +1015:09/09 18:52:59.434365 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 children info, the 1 child TID 0x8 +1016:09/09 18:52:59.434366 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 level:0, parentNum:0, childNum:2 +1017:09/09 18:52:59.434367 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 parents info, the 0 parent TID 0x6 +1018:09/09 18:52:59.434368 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 level:1, parentNum:1, childNum:0 +1019:09/09 18:52:59.434369 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 parents info, the 0 parent TID 0x6 +1020:09/09 18:52:59.434371 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 level:1, parentNum:1, childNum:0 +1021:09/09 18:52:59.434373 00166842 C QRY QID:0x987bae6a58a90008 job refId:0x5 created +1023:09/09 18:52:59.434377 00166842 C QRY QID:0x987bae6a58a90008 job start EXEC operation +1024:09/09 18:52:59.434381 00166842 C QRY QID:0x987bae6a58a90008 job status updated from NULL to INIT +1025:09/09 18:52:59.434382 00166842 C QRY QID:0x987bae6a58a90008 job status updated from INIT to EXECUTING +1026:09/09 18:52:59.434383 00166842 C QRY QID:0x987bae6a58a90008 sch job refId 0x5 started +1027:09/09 18:52:59.434385 00166842 C QRY QID:0x987bae6a58a90008 job no need flow ctrl, totalTableNum:0 +1028:09/09 18:52:59.434410 00166842 C QRY QID:0x987bae6a58a90008 job exec done, job status:EXECUTING, jobId:0x5 +1029:09/09 18:52:59.434414 00166842 C QRY QID:0x987bae6a58a90008 job end EXEC operation with code success +1031:09/09 18:52:59.434417 00166842 C QRY QID:0x987bae6a58a90008 ctg end to call user cb +1032:09/09 18:52:59.434424 00166842 C QRY QID:0x987bae6a58a90008, ctg job 0x5 freed +1035:09/09 18:52:59.434456 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to launch REMOTE task, execId 0, retry 1 +1036:09/09 18:52:59.434458 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to launch REMOTE task, execId 0, retry 1 +1037:09/09 18:52:59.434484 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task added to execTask list, numOfTasks:1 +1038:09/09 18:52:59.434485 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task added to execTask list, numOfTasks:2 +1039:09/09 18:52:59.434503 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 use execNode in plan as candidate addr, numOfEps:1 +1040:09/09 18:52:59.434515 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 use execNode in plan as candidate addr, numOfEps:1 +1050:09/09 18:52:59.434576 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 target candidateIdx 0, epInUse 0/1 +1052:09/09 18:52:59.434588 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to send query msg to node[3,localhost,6100], pTrans:0x2, pHandle:0x11 +1054:09/09 18:52:59.434593 00166842 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65a4003330, gtid:0x987bae6a58a90008:0x31de1d66a580001d +1055:09/09 18:52:59.434595 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 req msg sent, type:769, query +1056:09/09 18:52:59.434597 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task execNode added, execId:0, handle:0x11 +1059:09/09 18:52:59.434605 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 target candidateIdx 0, epInUse 0/1 +1062:09/09 18:52:59.434666 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to send query msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x12 +1065:09/09 18:52:59.434672 00166843 C RPC TSC send request at thread:00166860, dst:localhost:6100, app:0x7f65a8006120, gtid:0x987bae6a58a90008:0x31de1d66a580001e +1066:09/09 18:52:59.434696 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 req msg sent, type:769, query +1068:09/09 18:52:59.434700 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task execNode added, execId:0, handle:0x12 +1077:09/09 18:52:59.434797 00166862 C RPC TSC conn 0x7f65bc000c40 query is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:14, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d +1089:09/09 18:52:59.434934 00166860 C RPC TSC conn 0x7f65d4000c40 query is sent to 127.0.0.1:6100, local info:127.0.0.1:57868, seq:9, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e +1107:09/09 18:52:59.480608 00166862 C RPC TSC conn 0x7f65bc000c40 query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:130, seq:14, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d +1108:09/09 18:52:59.480658 00166860 C RPC TSC conn 0x7f65d4000c40 query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57868, len:130, seq:9, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e +1111:09/09 18:52:59.480728 00166847 C TSC processMsgFromServer handle 0x11, message: query-rsp, size:39, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001d +1114:09/09 18:52:59.480779 00166847 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 handle updated to 0x11 for execId 0 +1115:09/09 18:52:59.480795 00166847 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 taskOnSuccess, status:EXECUTING +1116:09/09 18:52:59.480809 00166847 C QRY PLAN: QID:0x987bae6a58a90008 set subplan execution node, groupId:2 +1119:09/09 18:52:59.480832 00166847 C TSC processMsgFromServer handle 0x12, message: query-rsp, size:39, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001e +1122:09/09 18:52:59.480854 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 handle updated to 0x12 for execId 0 +1123:09/09 18:52:59.480863 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 taskOnSuccess, status:EXECUTING +1124:09/09 18:52:59.480868 00166847 C QRY PLAN: QID:0x987bae6a58a90008 set subplan execution node, groupId:2 +1125:09/09 18:52:59.480872 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 all 2 children task done, start to launch parent task 0x6 +1129:09/09 18:52:59.480921 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to launch REMOTE task, execId 0, retry 1 +1130:09/09 18:52:59.480927 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task added to execTask list, numOfTasks:3 +1131:09/09 18:52:59.480959 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 target candidateIdx 0, epInUse 0/1 +1133:09/09 18:52:59.480982 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send merge-query msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 +1135:09/09 18:52:59.480998 00166847 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f6598006b80, gtid:0x987bae6a58a90008:0x31de1d66a580001f +1136:09/09 18:52:59.481028 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:771, merge-query +1137:09/09 18:52:59.481035 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task execNode added, execId:0, handle:0x13 +1143:09/09 18:52:59.481077 00166862 C RPC TSC conn 0x7f65bc000c40 merge-query is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:15, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f +1145:09/09 18:52:59.481938 00166862 C RPC TSC conn 0x7f65bc000c40 merge-query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:111, seq:15, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f +1147:09/09 18:52:59.481995 00166850 C TSC processMsgFromServer handle 0x13, message: merge-query-rsp, size:20, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001f +1150:09/09 18:52:59.482031 00166850 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 handle updated to 0x13 for execId 0 +1151:09/09 18:52:59.482042 00166850 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 taskOnSuccess, status:EXECUTING +1152:09/09 18:52:59.482049 00166850 C QRY QID:0x987bae6a58a90008 job status updated from EXECUTING to PARTIAL_SUCCEED +1153:09/09 18:52:59.482055 00166850 C QRY QID:0x987bae6a58a90008 execRes dumped, code: success +1154:09/09 18:52:59.482058 00166850 C QRY QID:0x987bae6a58a90008 sch start to invoke exec cb, code: success +1155:09/09 18:52:59.482062 00166850 C TSC 0x6 enter scheduler exec cb, code:success, reqId:0x987bae6a58a90008 +1162:09/09 18:52:59.482157 00166850 C QRY QID:0x987bae6a58a90008 sch end from exec cb, code: success +1168:09/09 18:52:59.482384 00166866 C QRY QID:0x987bae6a58a90008 job start FETCH operation +1169:09/09 18:52:59.482390 00166866 C QRY QID:0x987bae6a58a90008 job status updated from PARTIAL_SUCCEED to FETCHING +1170:09/09 18:52:59.482403 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send merge-fetch msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 +1172:09/09 18:52:59.482426 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65943151d0, gtid:0x987bae6a58a90008:0x31de1d66a5800020 +1173:09/09 18:52:59.482452 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:779, merge-fetch +1174:09/09 18:52:59.482460 00166866 C QRY QID:0x987bae6a58a90008 job end FETCH operation with code success +1178:09/09 18:52:59.482489 00166862 C RPC TSC conn 0x7f65bc000c40 merge-fetch is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:16, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800020 +1180:09/09 18:52:59.482714 00166862 C RPC TSC conn 0x7f65bc000c40 merge-fetch-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:1110, seq:16, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800020 +1182:09/09 18:52:59.482782 00166852 C TSC processMsgFromServer handle 0x13, message: merge-fetch-rsp, size:1019, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a5800020 +1185:09/09 18:52:59.482829 00166852 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 handle updated to 0x13 for execId 0 +1186:09/09 18:52:59.482835 00166852 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 got fetch rsp, rows:42, complete:1 +1187:09/09 18:52:59.482839 00166852 C QRY QID:0x987bae6a58a90008 job status updated from FETCHING to SUCCEED +1188:09/09 18:52:59.482842 00166852 C QRY QID:0x987bae6a58a90008 fetch done, totalRows:42 +1189:09/09 18:52:59.482845 00166852 C QRY QID:0x987bae6a58a90008 sch start to invoke fetch cb, code: success +1190:09/09 18:52:59.482848 00166852 C TSC 0x6 enter scheduler fetch cb, code:0 - success, reqId:0x987bae6a58a90008 +1191:09/09 18:52:59.482858 00166852 C TSC 0x6 fetch results, numOfRows:42 total Rows:42, complete:1, reqId:0x987bae6a58a90008 +1192:09/09 18:52:59.483360 00166852 C QRY QID:0x987bae6a58a90008 sch end from fetch cb, code: success +1196:09/09 18:52:59.483396 00166866 C TSC 0x987bae6a58a90008 taos_free_result start to free query +1198:09/09 18:52:59.483414 00166866 C QRY QID:0x987bae6a58a90008 start to free job 0x5, code:Query killed +1199:09/09 18:52:59.483419 00166866 C QRY QID:0x987bae6a58a90008 job status updated from SUCCEED to DROPPING +1200:09/09 18:52:59.483423 00166866 C QRY QID:0x987bae6a58a90008 job errCode updated to Query killed +1201:09/09 18:52:59.483426 00166866 C QRY QID:0x987bae6a58a90008 job failed with error Query killed +1202:09/09 18:52:59.483428 00166866 C QRY QID:0x987bae6a58a90008 job not in any operation, no need to post job res, status:DROPPING +1203:09/09 18:52:59.483432 00166866 C QRY QID:0x987bae6a58a90008 job removed from jobRef list, refId:0x5 +1205:09/09 18:52:59.483437 00166866 C QRY QID:0x987bae6a58a90008 begin to free sch job, refId:0x5, pointer:0x7f65a400d4a0 +1206:09/09 18:52:59.483449 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to send drop-task msg to node[3,localhost,6100], pTrans:0x2, pHandle:0x11 +1208:09/09 18:52:59.483462 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f6594302920, gtid:0x987bae6a58a90008:0x31de1d66a5800021 +1209:09/09 18:52:59.483487 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 req msg sent, type:783, drop-task +1210:09/09 18:52:59.483494 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to drop task's 0th execNode +1211:09/09 18:52:59.483498 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task has been dropped on 1 exec nodes +1212:09/09 18:52:59.483505 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send drop-task msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 +1214:09/09 18:52:59.483515 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65943031b0, gtid:0x987bae6a58a90008:0x31de1d66a5800022 +1215:09/09 18:52:59.483519 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:783, drop-task +1216:09/09 18:52:59.483521 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to drop task's 0th execNode +1217:09/09 18:52:59.483524 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task has been dropped on 1 exec nodes +1218:09/09 18:52:59.483528 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to send drop-task msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x12 +1220:09/09 18:52:59.483535 00166866 C RPC TSC send request at thread:00166860, dst:localhost:6100, app:0x7f659430e900, gtid:0x987bae6a58a90008:0x31de1d66a5800023 +1221:09/09 18:52:59.483560 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 req msg sent, type:783, drop-task +1222:09/09 18:52:59.483566 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to drop task's 0th execNode +1223:09/09 18:52:59.483570 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task has been dropped on 1 exec nodes +1226:09/09 18:52:59.483597 00166860 C RPC TSC conn 0x7f65d4000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57868, seq:10, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a5800023 +1228:09/09 18:52:59.483610 00166866 C QRY QID:0x987bae6a58a90008 sch job freed, refId:0x5, pointer:0x7f65a400d4a0 +1230:09/09 18:52:59.483622 00166866 C TSC 0x6 free Request from connObj: 0x2, reqId:0x987bae6a58a90008 elapsed:49.78 ms, current:0, app current:0 +1234:09/09 18:52:59.483739 00166862 C RPC TSC conn 0x7f65bc000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:17, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a5800021 +1236:09/09 18:52:59.483813 00166860 C RPC TSC conn 0x7f65d4000c40 receive release req, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e +1242:09/09 18:52:59.483854 00166862 C RPC TSC conn 0x7f65bc000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:18, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800022 +1246:09/09 18:52:59.484011 00166862 C RPC TSC conn 0x7f65bc000c40 receive release req, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d +1250:09/09 18:52:59.484124 00166862 C RPC TSC conn 0x7f65bc000c40 receive release req, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f diff --git a/sql1 b/sql1 new file mode 100644 index 0000000000..6924fc9a2a --- /dev/null +++ b/sql1 @@ -0,0 +1,141 @@ +974:09/09 18:52:59.433846 00166866 C TSC 0x6 new Request from connObj:0x2, current:1, app current:1, total:5, reqId:0x987bae6a58a90008 +975:09/09 18:52:59.433871 00166866 C TSC 0x6 SQL: select * from test.sp;, reqId:0x987bae6a58a90008 +977:09/09 18:52:59.433972 00166866 C QRY QID:0x987bae6a58a90008 the 0th task type [get db vgroup] initialized, dbFName:1.test +978:09/09 18:52:59.433978 00166866 C QRY QID:0x987bae6a58a90008 the 1th task type [bget table meta] initialized, dbNum:1, tbNum:1 +979:09/09 18:52:59.433982 00166866 C QRY QID:0x987bae6a58a90008 the 2th task type [bget table hash] initialized, dbNum:1, tbNum:1 +980:09/09 18:52:59.433986 00166866 C QRY QID:0x987bae6a58a90008 the 3th task type [get user] initialized, user:root +981:09/09 18:52:59.433991 00166866 C QRY QID:0x987bae6a58a90008, jobId: 0x5 initialized, task num 5, forceUpdate 0, elapsed time:0.03 ms +982:09/09 18:52:59.434002 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [0th] task +985:09/09 18:52:59.434031 00166866 C QRY QID:0x987bae6a58a90008 task 0 end with res success +986:09/09 18:52:59.434036 00166866 C QRY QID:0x987bae6a58a90008 task done: 1, total: 5 +987:09/09 18:52:59.434039 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [1th] task +990:09/09 18:52:59.434053 00166866 C QRY QID:0x987bae6a58a90008 task 1 end with res success +991:09/09 18:52:59.434056 00166866 C QRY QID:0x987bae6a58a90008 task done: 2, total: 5 +992:09/09 18:52:59.434059 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [2th] task +995:09/09 18:52:59.434072 00166866 C QRY QID:0x987bae6a58a90008 task 2 end with res success +996:09/09 18:52:59.434075 00166866 C QRY QID:0x987bae6a58a90008 task done: 3, total: 5 +997:09/09 18:52:59.434078 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [3th] task +1000:09/09 18:52:59.434090 00166866 C QRY QID:0x987bae6a58a90008 task 3 end with res success +1001:09/09 18:52:59.434104 00166866 C QRY QID:0x987bae6a58a90008 task done: 4, total: 5 +1002:09/09 18:52:59.434108 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [4th] task +1003:09/09 18:52:59.434114 00166866 C QRY QID:0x987bae6a58a90008 task 4 end with res success +1004:09/09 18:52:59.434170 00166842 C QRY QID:0x987bae6a58a90008 ctg start to call user cb with rsp success +1005:09/09 18:52:59.434187 00166842 C QRY 0x6 start to semantic analysis, reqId:0x987bae6a58a90008 +1006:09/09 18:52:59.434337 00166842 C TSC 0x987bae6a58a90008 vnode policy, use vnode list, num:2 +1008:09/09 18:52:59.434346 00166842 C QRY QID:0x987bae6a58a90008 set job levelIdx to 1 +1009:09/09 18:52:59.434352 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 task initialized, max times 6:6 +1010:09/09 18:52:59.434355 00166842 C QRY QID:0x987bae6a58a90008 level 0 initialized, taskNum:1 +1011:09/09 18:52:59.434358 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 task initialized, max times 6:12 +1012:09/09 18:52:59.434360 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 task initialized, max times 6:12 +1013:09/09 18:52:59.434361 00166842 C QRY QID:0x987bae6a58a90008 level 1 initialized, taskNum:2 +1014:09/09 18:52:59.434363 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 children info, the 0 child TID 0x7 +1015:09/09 18:52:59.434365 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 children info, the 1 child TID 0x8 +1016:09/09 18:52:59.434366 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 level:0, parentNum:0, childNum:2 +1017:09/09 18:52:59.434367 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 parents info, the 0 parent TID 0x6 +1018:09/09 18:52:59.434368 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 level:1, parentNum:1, childNum:0 +1019:09/09 18:52:59.434369 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 parents info, the 0 parent TID 0x6 +1020:09/09 18:52:59.434371 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 level:1, parentNum:1, childNum:0 +1021:09/09 18:52:59.434373 00166842 C QRY QID:0x987bae6a58a90008 job refId:0x5 created +1023:09/09 18:52:59.434377 00166842 C QRY QID:0x987bae6a58a90008 job start EXEC operation +1024:09/09 18:52:59.434381 00166842 C QRY QID:0x987bae6a58a90008 job status updated from NULL to INIT +1025:09/09 18:52:59.434382 00166842 C QRY QID:0x987bae6a58a90008 job status updated from INIT to EXECUTING +1026:09/09 18:52:59.434383 00166842 C QRY QID:0x987bae6a58a90008 sch job refId 0x5 started +1027:09/09 18:52:59.434385 00166842 C QRY QID:0x987bae6a58a90008 job no need flow ctrl, totalTableNum:0 +1028:09/09 18:52:59.434410 00166842 C QRY QID:0x987bae6a58a90008 job exec done, job status:EXECUTING, jobId:0x5 +1029:09/09 18:52:59.434414 00166842 C QRY QID:0x987bae6a58a90008 job end EXEC operation with code success +1031:09/09 18:52:59.434417 00166842 C QRY QID:0x987bae6a58a90008 ctg end to call user cb +1032:09/09 18:52:59.434424 00166842 C QRY QID:0x987bae6a58a90008, ctg job 0x5 freed +1035:09/09 18:52:59.434456 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to launch REMOTE task, execId 0, retry 1 +1036:09/09 18:52:59.434458 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to launch REMOTE task, execId 0, retry 1 +1037:09/09 18:52:59.434484 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task added to execTask list, numOfTasks:1 +1038:09/09 18:52:59.434485 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task added to execTask list, numOfTasks:2 +1039:09/09 18:52:59.434503 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 use execNode in plan as candidate addr, numOfEps:1 +1040:09/09 18:52:59.434515 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 use execNode in plan as candidate addr, numOfEps:1 +1050:09/09 18:52:59.434576 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 target candidateIdx 0, epInUse 0/1 +1052:09/09 18:52:59.434588 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to send query msg to node[3,localhost,6100], pTrans:0x2, pHandle:0x11 +1054:09/09 18:52:59.434593 00166842 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65a4003330, gtid:0x987bae6a58a90008:0x31de1d66a580001d +1055:09/09 18:52:59.434595 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 req msg sent, type:769, query +1056:09/09 18:52:59.434597 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task execNode added, execId:0, handle:0x11 +1059:09/09 18:52:59.434605 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 target candidateIdx 0, epInUse 0/1 +1062:09/09 18:52:59.434666 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to send query msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x12 +1065:09/09 18:52:59.434672 00166843 C RPC TSC send request at thread:00166860, dst:localhost:6100, app:0x7f65a8006120, gtid:0x987bae6a58a90008:0x31de1d66a580001e +1066:09/09 18:52:59.434696 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 req msg sent, type:769, query +1068:09/09 18:52:59.434700 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task execNode added, execId:0, handle:0x12 +1077:09/09 18:52:59.434797 00166862 C RPC TSC conn 0x7f65bc000c40 query is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:14, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d +1089:09/09 18:52:59.434934 00166860 C RPC TSC conn 0x7f65d4000c40 query is sent to 127.0.0.1:6100, local info:127.0.0.1:57868, seq:9, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e +1107:09/09 18:52:59.480608 00166862 C RPC TSC conn 0x7f65bc000c40 query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:130, seq:14, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d +1108:09/09 18:52:59.480658 00166860 C RPC TSC conn 0x7f65d4000c40 query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57868, len:130, seq:9, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e +1111:09/09 18:52:59.480728 00166847 C TSC processMsgFromServer handle 0x11, message: query-rsp, size:39, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001d +1114:09/09 18:52:59.480779 00166847 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 handle updated to 0x11 for execId 0 +1115:09/09 18:52:59.480795 00166847 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 taskOnSuccess, status:EXECUTING +1116:09/09 18:52:59.480809 00166847 C QRY PLAN: QID:0x987bae6a58a90008 set subplan execution node, groupId:2 +1119:09/09 18:52:59.480832 00166847 C TSC processMsgFromServer handle 0x12, message: query-rsp, size:39, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001e +1122:09/09 18:52:59.480854 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 handle updated to 0x12 for execId 0 +1123:09/09 18:52:59.480863 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 taskOnSuccess, status:EXECUTING +1124:09/09 18:52:59.480868 00166847 C QRY PLAN: QID:0x987bae6a58a90008 set subplan execution node, groupId:2 +1125:09/09 18:52:59.480872 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 all 2 children task done, start to launch parent task 0x6 +1129:09/09 18:52:59.480921 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to launch REMOTE task, execId 0, retry 1 +1130:09/09 18:52:59.480927 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task added to execTask list, numOfTasks:3 +1131:09/09 18:52:59.480959 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 target candidateIdx 0, epInUse 0/1 +1133:09/09 18:52:59.480982 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send merge-query msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 +1135:09/09 18:52:59.480998 00166847 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f6598006b80, gtid:0x987bae6a58a90008:0x31de1d66a580001f +1136:09/09 18:52:59.481028 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:771, merge-query +1137:09/09 18:52:59.481035 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task execNode added, execId:0, handle:0x13 +1143:09/09 18:52:59.481077 00166862 C RPC TSC conn 0x7f65bc000c40 merge-query is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:15, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f +1145:09/09 18:52:59.481938 00166862 C RPC TSC conn 0x7f65bc000c40 merge-query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:111, seq:15, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f +1147:09/09 18:52:59.481995 00166850 C TSC processMsgFromServer handle 0x13, message: merge-query-rsp, size:20, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001f +1150:09/09 18:52:59.482031 00166850 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 handle updated to 0x13 for execId 0 +1151:09/09 18:52:59.482042 00166850 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 taskOnSuccess, status:EXECUTING +1152:09/09 18:52:59.482049 00166850 C QRY QID:0x987bae6a58a90008 job status updated from EXECUTING to PARTIAL_SUCCEED +1153:09/09 18:52:59.482055 00166850 C QRY QID:0x987bae6a58a90008 execRes dumped, code: success +1154:09/09 18:52:59.482058 00166850 C QRY QID:0x987bae6a58a90008 sch start to invoke exec cb, code: success +1155:09/09 18:52:59.482062 00166850 C TSC 0x6 enter scheduler exec cb, code:success, reqId:0x987bae6a58a90008 +1162:09/09 18:52:59.482157 00166850 C QRY QID:0x987bae6a58a90008 sch end from exec cb, code: success +1168:09/09 18:52:59.482384 00166866 C QRY QID:0x987bae6a58a90008 job start FETCH operation +1169:09/09 18:52:59.482390 00166866 C QRY QID:0x987bae6a58a90008 job status updated from PARTIAL_SUCCEED to FETCHING +1170:09/09 18:52:59.482403 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send merge-fetch msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 +1172:09/09 18:52:59.482426 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65943151d0, gtid:0x987bae6a58a90008:0x31de1d66a5800020 +1173:09/09 18:52:59.482452 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:779, merge-fetch +1174:09/09 18:52:59.482460 00166866 C QRY QID:0x987bae6a58a90008 job end FETCH operation with code success +1178:09/09 18:52:59.482489 00166862 C RPC TSC conn 0x7f65bc000c40 merge-fetch is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:16, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800020 +1180:09/09 18:52:59.482714 00166862 C RPC TSC conn 0x7f65bc000c40 merge-fetch-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:1110, seq:16, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800020 +1182:09/09 18:52:59.482782 00166852 C TSC processMsgFromServer handle 0x13, message: merge-fetch-rsp, size:1019, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a5800020 +1185:09/09 18:52:59.482829 00166852 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 handle updated to 0x13 for execId 0 +1186:09/09 18:52:59.482835 00166852 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 got fetch rsp, rows:42, complete:1 +1187:09/09 18:52:59.482839 00166852 C QRY QID:0x987bae6a58a90008 job status updated from FETCHING to SUCCEED +1188:09/09 18:52:59.482842 00166852 C QRY QID:0x987bae6a58a90008 fetch done, totalRows:42 +1189:09/09 18:52:59.482845 00166852 C QRY QID:0x987bae6a58a90008 sch start to invoke fetch cb, code: success +1190:09/09 18:52:59.482848 00166852 C TSC 0x6 enter scheduler fetch cb, code:0 - success, reqId:0x987bae6a58a90008 +1191:09/09 18:52:59.482858 00166852 C TSC 0x6 fetch results, numOfRows:42 total Rows:42, complete:1, reqId:0x987bae6a58a90008 +1192:09/09 18:52:59.483360 00166852 C QRY QID:0x987bae6a58a90008 sch end from fetch cb, code: success +1196:09/09 18:52:59.483396 00166866 C TSC 0x987bae6a58a90008 taos_free_result start to free query +1198:09/09 18:52:59.483414 00166866 C QRY QID:0x987bae6a58a90008 start to free job 0x5, code:Query killed +1199:09/09 18:52:59.483419 00166866 C QRY QID:0x987bae6a58a90008 job status updated from SUCCEED to DROPPING +1200:09/09 18:52:59.483423 00166866 C QRY QID:0x987bae6a58a90008 job errCode updated to Query killed +1201:09/09 18:52:59.483426 00166866 C QRY QID:0x987bae6a58a90008 job failed with error Query killed +1202:09/09 18:52:59.483428 00166866 C QRY QID:0x987bae6a58a90008 job not in any operation, no need to post job res, status:DROPPING +1203:09/09 18:52:59.483432 00166866 C QRY QID:0x987bae6a58a90008 job removed from jobRef list, refId:0x5 +1205:09/09 18:52:59.483437 00166866 C QRY QID:0x987bae6a58a90008 begin to free sch job, refId:0x5, pointer:0x7f65a400d4a0 +1206:09/09 18:52:59.483449 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to send drop-task msg to node[3,localhost,6100], pTrans:0x2, pHandle:0x11 +1208:09/09 18:52:59.483462 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f6594302920, gtid:0x987bae6a58a90008:0x31de1d66a5800021 +1209:09/09 18:52:59.483487 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 req msg sent, type:783, drop-task +1210:09/09 18:52:59.483494 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to drop task's 0th execNode +1211:09/09 18:52:59.483498 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task has been dropped on 1 exec nodes +1212:09/09 18:52:59.483505 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send drop-task msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 +1214:09/09 18:52:59.483515 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65943031b0, gtid:0x987bae6a58a90008:0x31de1d66a5800022 +1215:09/09 18:52:59.483519 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:783, drop-task +1216:09/09 18:52:59.483521 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to drop task's 0th execNode +1217:09/09 18:52:59.483524 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task has been dropped on 1 exec nodes +1218:09/09 18:52:59.483528 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to send drop-task msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x12 +1220:09/09 18:52:59.483535 00166866 C RPC TSC send request at thread:00166860, dst:localhost:6100, app:0x7f659430e900, gtid:0x987bae6a58a90008:0x31de1d66a5800023 +1221:09/09 18:52:59.483560 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 req msg sent, type:783, drop-task +1222:09/09 18:52:59.483566 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to drop task's 0th execNode +1223:09/09 18:52:59.483570 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task has been dropped on 1 exec nodes +1226:09/09 18:52:59.483597 00166860 C RPC TSC conn 0x7f65d4000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57868, seq:10, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a5800023 +1228:09/09 18:52:59.483610 00166866 C QRY QID:0x987bae6a58a90008 sch job freed, refId:0x5, pointer:0x7f65a400d4a0 +1230:09/09 18:52:59.483622 00166866 C TSC 0x6 free Request from connObj: 0x2, reqId:0x987bae6a58a90008 elapsed:49.78 ms, current:0, app current:0 +1234:09/09 18:52:59.483739 00166862 C RPC TSC conn 0x7f65bc000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:17, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a5800021 +1236:09/09 18:52:59.483813 00166860 C RPC TSC conn 0x7f65d4000c40 receive release req, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e +1242:09/09 18:52:59.483854 00166862 C RPC TSC conn 0x7f65bc000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:18, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800022 +1246:09/09 18:52:59.484011 00166862 C RPC TSC conn 0x7f65bc000c40 receive release req, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d +1250:09/09 18:52:59.484124 00166862 C RPC TSC conn 0x7f65bc000c40 receive release req, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f From 086333df519320314a27e42ff9718858cfce5c22 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 9 Sep 2024 22:06:45 +0800 Subject: [PATCH 058/240] opt transport --- source/libs/transport/inc/transComm.h | 7 ++++--- source/libs/transport/src/transCli.c | 2 +- source/libs/transport/src/transSvr.c | 24 +++++++----------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 4c5b1511b2..bae4aac2c4 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -351,9 +351,10 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType); // request list typedef struct STransReq { - queue q; - queue node; - void* conn; + queue q; // gloabl queue node + queue node; // req queue node + void* conn; + uv_write_t req; } STransReq; void transReqQueueInit(queue* q); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 25ac74d9c0..8d811bf755 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3633,7 +3633,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } code = transHeapGet(pHeap, &pConn); - // if (pConn && taosHashGetSize(pConn->pQTable) > 0) { + // if (pConn && taosHashGetSifze(pConn->pQTable) > 0) { // tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, // pConn->reqRefCnt); return NULL; // } /*else { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 53e9c0f9b1..22db1d26b3 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -625,26 +625,15 @@ void uvOnTimeoutCb(uv_timer_t* handle) { void uvOnSendCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); - queue q; - QUEUE_INIT(&q); - - STransReq* userReq = transReqQueueRemove(req); + STransReq* userReq = req->data; SSvrConn* conn = userReq->conn; - - queue* src = &userReq->node; - while (!QUEUE_IS_EMPTY(src)) { - queue* head = QUEUE_HEAD(src); - QUEUE_REMOVE(head); - QUEUE_PUSH(&q, head); - // } - } - // QUEUE_MOVE(src, &q); + queue* src = &userReq->node; tDebug("%s conn %p send data", transLabel(conn->pInst), conn); if (status == 0) { - while (!QUEUE_IS_EMPTY(&q)) { - queue* head = QUEUE_HEAD(&q); + while (!QUEUE_IS_EMPTY(src)) { + queue* head = QUEUE_HEAD(&src); QUEUE_REMOVE(head); SSvrMsg* smsg = QUEUE_DATA(head, SSvrMsg, sendReq); @@ -660,6 +649,7 @@ void uvOnSendCb(uv_write_t* req, int status) { conn->broken = true; } } + taosMemoryFree(userReq); transUnrefSrvHandle(conn); } static void uvOnPipeWriteCb(uv_write_t* req, int status) { @@ -793,10 +783,10 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { STransReq* pWreq = taosMemoryCalloc(1, sizeof(STransReq)); pWreq->conn = pConn; QUEUE_INIT(&pWreq->q); - QUEUE_MOVE(&sendReqNode, &pWreq->node); + pWreq->req.data = pWreq; - uv_write_t* req = transReqQueuePush(&pConn->wreqQueue, pWreq); + uv_write_t* req = &pWreq->req; if (req == NULL) { if (!uv_is_closing((uv_handle_t*)(pConn->pTcp))) { tError("conn %p failed to write data, reason:%s", pConn, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); From debf225c151ebdbca1e7c5d2b087e352eb82c40c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 9 Sep 2024 22:16:47 +0800 Subject: [PATCH 059/240] opt transport --- source/libs/transport/inc/transComm.h | 6 +++--- source/libs/transport/src/transComm.c | 6 +++--- source/libs/transport/src/transSvr.c | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index bae4aac2c4..451109cd59 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -350,15 +350,15 @@ void* transCtxDumpVal(STransCtx* ctx, int32_t key); void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType); // request list -typedef struct STransReq { +typedef struct SWriteReq { queue q; // gloabl queue node queue node; // req queue node void* conn; uv_write_t req; -} STransReq; +} SWriteReq; void transReqQueueInit(queue* q); -void* transReqQueuePush(queue* q, STransReq* req); +void* transReqQueuePush(queue* q, SWriteReq* req); void* transReqQueueRemove(void* arg); void transReqQueueClear(queue* q); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 326fd434ec..add463bb45 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -411,7 +411,7 @@ void transReqQueueInit(queue* q) { // init req queue QUEUE_INIT(q); } -void* transReqQueuePush(queue* q, STransReq* userReq) { +void* transReqQueuePush(queue* q, SWriteReq* userReq) { uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); req->data = userReq; @@ -422,7 +422,7 @@ void* transReqQueueRemove(void* arg) { void* ret = NULL; uv_write_t* req = arg; - STransReq* userReq = req ? req->data : NULL; + SWriteReq* userReq = req ? req->data : NULL; if (req == NULL) return NULL; QUEUE_REMOVE(&userReq->q); @@ -432,7 +432,7 @@ void transReqQueueClear(queue* q) { while (!QUEUE_IS_EMPTY(q)) { queue* h = QUEUE_HEAD(q); QUEUE_REMOVE(h); - STransReq* req = QUEUE_DATA(h, STransReq, q); + SWriteReq* req = QUEUE_DATA(h, SWriteReq, q); taosMemoryFree(req); } } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 22db1d26b3..a882ea7e68 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -25,7 +25,7 @@ typedef struct { } SSvrRegArg; typedef struct SSvrConn { - T_REF_DECLARE() + int32_t ref; uv_tcp_t* pTcp; queue wreqQueue; uv_timer_t pTimer; @@ -625,7 +625,7 @@ void uvOnTimeoutCb(uv_timer_t* handle) { void uvOnSendCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); - STransReq* userReq = req->data; + SWriteReq* userReq = req->data; SSvrConn* conn = userReq->conn; queue* src = &userReq->node; @@ -780,7 +780,7 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { transRefSrvHandle(pConn); - STransReq* pWreq = taosMemoryCalloc(1, sizeof(STransReq)); + SWriteReq* pWreq = taosMemoryCalloc(1, sizeof(SWriteReq)); pWreq->conn = pConn; QUEUE_INIT(&pWreq->q); QUEUE_MOVE(&sendReqNode, &pWreq->node); @@ -843,7 +843,7 @@ static void destroyAllConn(SWorkThrd* pThrd) { QUEUE_INIT(h); SSvrConn* c = QUEUE_DATA(h, SSvrConn, queue); - while (T_REF_VAL_GET(c) >= 2) { + while (c->ref >= 2) { transUnrefSrvHandle(c); } transUnrefSrvHandle(c); @@ -1743,17 +1743,19 @@ void transRefSrvHandle(void* handle) { if (handle == NULL) { return; } - int ref = T_REF_INC((SSvrConn*)handle); - tTrace("conn %p ref count:%d", handle, ref); + SSvrConn* pConn = handle; + pConn->ref++; + tTrace("conn %p ref count:%d", handle, pConn->ref); } void transUnrefSrvHandle(void* handle) { if (handle == NULL) { return; } - int ref = T_REF_DEC((SSvrConn*)handle); - tTrace("conn %p ref count:%d", handle, ref); - if (ref == 0) { + SSvrConn* pConn = handle; + pConn->ref--; + tTrace("conn %p ref count:%d", handle, pConn->ref); + if (pConn->ref == 0) { destroyConn((SSvrConn*)handle, true); } } From b719f2258aacc476835e5119bdabe627caf3ff2a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 10 Sep 2024 08:55:48 +0800 Subject: [PATCH 060/240] opt transport --- source/libs/transport/src/transCli.c | 272 ++++++++++++++------------- source/libs/transport/src/transSvr.c | 72 ++----- 2 files changed, 164 insertions(+), 180 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 8d811bf755..712b278e31 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -55,7 +55,7 @@ typedef struct { } SCliBatch; typedef struct SCliConn { - T_REF_DECLARE() + int32_t ref; uv_connect_t connReq; uv_stream_t* stream; queue wreqQueue; @@ -101,6 +101,18 @@ typedef struct SCliConn { SHashObj* pQTable; } SCliConn; +// #define TRANS_CONN_REF_INC(tconn) \ +// do { \ +// if (tcond) (tconn)->ref++; \ +// } while (0) + +// #define TRANS_CONN_REF_DEC(tcond) if (tcond) (tconn)\ +// do { \ +// if (tcond) (tconn)->ref--; \ +// } while (0) + +#define TRANS_CONN_REF_GET(tconn) ((tconn) ? (tconn)->ref : 0) + typedef struct { SCliConn* conn; void* arg; @@ -252,7 +264,7 @@ static FORCE_INLINE void cliMayUpdateFqdnCache(SHashObj* cache, char* dst); // process data read from server, add decompress etc later // handle except about conn static void cliHandleExcept(SCliConn* conn, int32_t code); -static void cliReleaseUnfinishedMsg(SCliConn* conn); +// static void cliReleaseUnfinishedMsg(SCliConn* conn); static void cliHandleFastFail(SCliConn* pConn, int status); static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code); @@ -328,59 +340,59 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); #define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para)) #define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pInst))->label) -#define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ - do { \ - int i = 0, sz = transQueueSize(&conn->reqs); \ - for (; i < sz; i++) { \ - pReq = transQueueGet(&conn->reqs, i); \ - if (pReq->ctx != NULL && (uint64_t)pReq->ctx->ahandle == ahandle) { \ - break; \ - } \ - } \ - if (i == sz) { \ - pReq = NULL; \ - } else { \ - pReq = transQueueRm(&conn->reqs, i); \ - } \ - } while (0) +// #define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ +// do { \ +// int i = 0, sz = transQueueSize(&conn->reqs); \ +// for (; i < sz; i++) { \ +// pReq = transQueueGet(&conn->reqs, i); \ +// if (pReq->ctx != NULL && (uint64_t)pReq->ctx->ahandle == ahandle) { \ +// break; \ +// } \ +// } \ +// if (i == sz) { \ +// pReq = NULL; \ +// } else { \ +// pReq = transQueueRm(&conn->reqs, i); \ +// } \ +// } while (0) -#define CONN_GET_NEXT_SENDMSG(conn) \ - do { \ - int i = 0; \ - do { \ - pCliMsg = transQueueGet(&conn->reqs, i++); \ - if (pCliMsg && 0 == pCliMsg->sent) { \ - break; \ - } \ - } while (pCliMsg != NULL); \ - if (pCliMsg == NULL) { \ - goto _RETURN; \ - } \ - } while (0) +// #define CONN_GET_NEXT_SENDMSG(conn) \ +// do { \ +// int i = 0; \ +// do { \ +// pCliMsg = transQueueGet(&conn->reqs, i++); \ +// if (pCliMsg && 0 == pCliMsg->sent) { \ +// break; \ +// } \ +// } while (pCliMsg != NULL); \ +// if (pCliMsg == NULL) { \ +// goto _RETURN; \ +// } \ +// } while (0) -static int32_t cliConnFindToSendMsg(SCliConn* pConn, SCliReq** pReq) { - int32_t code = 0; - for (int32_t i = 0; i < transQueueSize(&pConn->reqs); i++) { - SCliReq* p = transQueueGet(&pConn->reqs, i); - if (p->sent == 0) { - *pReq = p; - return 0; - } - } - return TSDB_CODE_OUT_OF_RANGE; -} -#define CONN_SET_PERSIST_BY_APP(conn) \ - do { \ - if (conn->status == ConnNormal) { \ - conn->status = ConnAcquire; \ - transRefCliHandle(conn); \ - } \ - } while (0) +// static int32_t cliConnFindToSendMsg(SCliConn* pConn, SCliReq** pReq) { +// int32_t code = 0; +// for (int32_t i = 0; i < transQueueSize(&pConn->reqs); i++) { +// SCliReq* p = transQueueGet(&pConn->reqs, i); +// if (p->sent == 0) { +// *pReq = p; +// return 0; +// } +// } +// return TSDB_CODE_OUT_OF_RANGE; +// } +// #define CONN_SET_PERSIST_BY_APP(conn) \ +// do { \ +// if (conn->status == ConnNormal) { \ +// conn->status = ConnAcquire; \ +// transRefCliHandle(conn); \ +// } \ +// } while (0) #define CONN_NO_PERSIST_BY_APP(conn) \ - (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) -#define CONN_RELEASE_BY_SERVER(conn) \ - (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) + (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && TRANS_CONN_REF_GET(conn) == 1) +// #define CONN_RELEASE_BY_SERVER(conn) \ +// (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && TRANS_CONN_REF_GET(conn) == 1) #define REQUEST_NO_RESP(msg) ((msg)->info.noResp == 1) #define REQUEST_PERSIS_HANDLE(msg) ((msg)->info.persistHandle == 1) @@ -400,63 +412,63 @@ static int32_t cliConnFindToSendMsg(SCliConn* pConn, SCliReq** pReq) { static void* cliWorkThread(void* arg); -static void cliReleaseUnfinishedMsg(SCliConn* conn) { - SCliThrd* pThrd = conn->hostThrd; +// static void cliReleaseUnfinishedMsg(SCliConn* conn) { +// SCliThrd* pThrd = conn->hostThrd; - for (int i = 0; i < transQueueSize(&conn->reqs); i++) { - SCliReq* msg = transQueueGet(&conn->reqs, i); - if (msg != NULL && msg->ctx != NULL && msg->ctx->ahandle != (void*)0x9527) { - if (conn->ctx.freeFunc != NULL && msg->ctx->ahandle != NULL) { - conn->ctx.freeFunc(msg->ctx->ahandle); - } else if (msg->msg.info.notFreeAhandle == 0 && msg->ctx->ahandle != NULL && pThrd->destroyAhandleFp != NULL) { - tDebug("%s conn %p destroy unfinished ahandle %p", CONN_GET_INST_LABEL(conn), conn, msg->ctx->ahandle); - pThrd->destroyAhandleFp(msg->ctx->ahandle); - } - } - destroyReq(msg); - } - transQueueClear(&conn->reqs); - memset(&conn->ctx, 0, sizeof(conn->ctx)); -} -bool cliMaySendCachedMsg(SCliConn* conn) { - if (!transQueueEmpty(&conn->reqs)) { - SCliReq* pCliMsg = NULL; - CONN_GET_NEXT_SENDMSG(conn); - (void)cliSend2(conn); - return true; - } - return false; -_RETURN: - return false; -} -bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { - if (refId == 0) return false; - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh == NULL) { - tDebug("release conn %p, refId: %" PRId64 "", conn, refId); - return false; - } - taosWLockLatch(&exh->latch); - if (exh->handle == NULL) exh->handle = conn; - exh->inited = 1; - exh->pThrd = conn->hostThrd; - if (!QUEUE_IS_EMPTY(&exh->q)) { - queue* h = QUEUE_HEAD(&exh->q); - QUEUE_REMOVE(h); - taosWUnLockLatch(&exh->latch); - SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); - transCtxMerge(&conn->ctx, &t->ctx->userCtx); - (void)transQueuePush(&conn->reqs, t); - tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); - (void)transReleaseExHandle(transGetRefMgt(), refId); - (void)cliSend2(conn); - return true; - } - taosWUnLockLatch(&exh->latch); - tDebug("empty conn %p, refId: %" PRId64 "", conn, refId); - (void)transReleaseExHandle(transGetRefMgt(), refId); - return false; -} +// for (int i = 0; i < transQueueSize(&conn->reqs); i++) { +// SCliReq* msg = transQueueGet(&conn->reqs, i); +// if (msg != NULL && msg->ctx != NULL && msg->ctx->ahandle != (void*)0x9527) { +// if (conn->ctx.freeFunc != NULL && msg->ctx->ahandle != NULL) { +// conn->ctx.freeFunc(msg->ctx->ahandle); +// } else if (msg->msg.info.notFreeAhandle == 0 && msg->ctx->ahandle != NULL && pThrd->destroyAhandleFp != NULL) { +// tDebug("%s conn %p destroy unfinished ahandle %p", CONN_GET_INST_LABEL(conn), conn, msg->ctx->ahandle); +// pThrd->destroyAhandleFp(msg->ctx->ahandle); +// } +// } +// destroyReq(msg); +// } +// transQueueClear(&conn->reqs); +// memset(&conn->ctx, 0, sizeof(conn->ctx)); +// } +// bool cliMaySendCachedMsg(SCliConn* conn) { +// if (!transQueueEmpty(&conn->reqs)) { +// SCliReq* pCliMsg = NULL; +// CONN_GET_NEXT_SENDMSG(conn); +// (void)cliSend2(conn); +// return true; +// } +// return false; +// _RETURN: +// return false; +// } +// bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { +// if (refId == 0) return false; +// SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); +// if (exh == NULL) { +// tDebug("release conn %p, refId: %" PRId64 "", conn, refId); +// return false; +// } +// taosWLockLatch(&exh->latch); +// if (exh->handle == NULL) exh->handle = conn; +// exh->inited = 1; +// exh->pThrd = conn->hostThrd; +// if (!QUEUE_IS_EMPTY(&exh->q)) { +// queue* h = QUEUE_HEAD(&exh->q); +// QUEUE_REMOVE(h); +// taosWUnLockLatch(&exh->latch); +// SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); +// transCtxMerge(&conn->ctx, &t->ctx->userCtx); +// (void)transQueuePush(&conn->reqs, t); +// tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); +// (void)transReleaseExHandle(transGetRefMgt(), refId); +// (void)cliSend2(conn); +// return true; +// } +// taosWUnLockLatch(&exh->latch); +// tDebug("empty conn %p, refId: %" PRId64 "", conn, refId); +// (void)transReleaseExHandle(transGetRefMgt(), refId); +// return false; +// } int32_t cliGetConnTimer(SCliThrd* pThrd, SCliConn* pConn) { uv_timer_t* timer = taosArrayGetSize(pThrd->timerList) > 0 ? *(uv_timer_t**)taosArrayPop(pThrd->timerList) : NULL; @@ -624,8 +636,10 @@ void cliHandleResp2(SCliConn* conn) { code = cliBuildRespFromCont(NULL, &resp, pHead); code = cliNotifyCb(conn, NULL, &resp); return; + } else { + tDebug("%s conn %p recv unexpected packet, seqNum:%d,qId:%ld reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, + qId, tstrerror(code)); } - if (code != 0) { tDebug("%s conn %p recv unexpected packet, seqNum:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, tstrerror(code)); @@ -664,7 +678,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { // if (transQueueEmpty(&pConn->reqs)) { // if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { // tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); - // if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); + // if (TRANS_CONN_REF_GET(pConn) > 1) transUnrefCliHandle(pConn); // transUnrefCliHandle(pConn); // return; // } @@ -725,13 +739,13 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { // } // } // destroyReq(pReq); - // tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn)); + // tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, TRANS_CONN_REF_GET(pConn)); // } while (!transQueueEmpty(&pConn->reqs)); - // if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn); + // if (TRANS_CONN_REF_GET(pConn) > 1) transUnrefCliHandle(pConn); // transUnrefCliHandle(pConn); } void cliHandleExcept(SCliConn* conn, int32_t code) { - tTrace("%s conn %p except ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); + tTrace("%s conn %p except ref:%d", CONN_GET_INST_LABEL(conn), conn, TRANS_CONN_REF_GET(conn)); if (code != TSDB_CODE_RPC_FQDN_ERROR) { code = -1; } @@ -742,7 +756,7 @@ void cliConnTimeout(uv_timer_t* handle) { SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; - tTrace("%s conn %p conn timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); + tTrace("%s conn %p conn timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, TRANS_CONN_REF_GET(conn)); cliResetConnTimer(conn); cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); @@ -751,7 +765,7 @@ void cliConnTimeout(uv_timer_t* handle) { 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)); + tTrace("%s conn %p timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, TRANS_CONN_REF_GET(conn)); (void)uv_read_stop(conn->stream); cliHandleExceptImpl(conn, TSDB_CODE_RPC_TIMEOUT); } @@ -1043,7 +1057,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { SCliThrd* thrd = conn->hostThrd; cliResetConnTimer(conn); - if (T_REF_VAL_GET(conn) > 1) { + if (TRANS_CONN_REF_GET(conn) > 1) { transUnrefCliHandle(conn); } cliDestroyConnMsgs(conn, false); @@ -1189,7 +1203,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } if (nread < 0) { tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), - T_REF_VAL_GET(conn)); + TRANS_CONN_REF_GET(conn)); conn->broken = true; cliHandleExcept(conn, -1); } @@ -1427,7 +1441,7 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { } } - if (T_REF_VAL_GET(conn) > 1) transUnrefCliHandle(conn); + if (TRANS_CONN_REF_GET(conn) > 1) transUnrefCliHandle(conn); transUnrefCliHandle(conn); } @@ -1784,7 +1798,7 @@ static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { (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) { + if (TRANS_CONN_REF_GET(conn) == 2) { transUnrefCliHandle(conn); if (!transQueuePush(&conn->reqs, pReq)) { return; @@ -1824,7 +1838,7 @@ static void cliHandleFreeById(SCliThrd* pThrd, SCliReq* pReq) { // already recv, and notify upper layer TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); } else { - while (T_REF_VAL_GET(conn) >= 1) { + while (TRANS_CONN_REF_GET(conn) >= 1) { transUnrefCliHandle(conn); } return; @@ -2306,7 +2320,7 @@ static void cliAsyncCb(uv_async_t* handle) { void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { transCtxCleanup(&conn->ctx); - cliReleaseUnfinishedMsg(conn); + // cliReleaseUnfinishedMsg(conn); if (destroy == 1) { transQueueDestroy(&conn->reqs); } else { @@ -3062,21 +3076,25 @@ void transCloseClient(void* arg) { taosMemoryFree(cli); } void transRefCliHandle(void* handle) { + int32_t ref = 0; if (handle == NULL) { return; } - int ref = T_REF_INC((SCliConn*)handle); - tTrace("%s conn %p ref %d", CONN_GET_INST_LABEL((SCliConn*)handle), handle, ref); - UNUSED(ref); + SCliConn* conn = (SCliConn*)handle; + conn->ref++; + + tTrace("%s conn %p ref %d", CONN_GET_INST_LABEL(conn), conn, conn->ref); } void transUnrefCliHandle(void* handle) { if (handle == NULL) { return; } - int ref = T_REF_DEC((SCliConn*)handle); - tTrace("%s conn %p ref:%d", CONN_GET_INST_LABEL((SCliConn*)handle), handle, ref); - if (ref == 0) { - cliDestroyConn((SCliConn*)handle, true); + SCliConn* conn = (SCliConn*)handle; + conn->ref--; + + tTrace("%s conn %p ref:%d", CONN_GET_INST_LABEL(conn), conn, conn->ref); + if (conn->ref == 0) { + cliDestroyConn(conn, true); } } static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t handle) { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index a882ea7e68..97afc77b9a 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -38,8 +38,8 @@ typedef struct SSvrConn { void* hostThrd; STransQueue srvMsgs; - SSvrRegArg regArg; - bool broken; // conn broken; + // SSvrRegArg regArg; + bool broken; // conn broken; ConnStatus status; @@ -168,7 +168,7 @@ static void uvNotifyLinkBrokenToApp(SSvrConn* conn); static FORCE_INLINE void destroySmsg(SSvrMsg* smsg); 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 FORCE_INLINE void destroyConnRegArg(SSvrConn* conn); static int32_t reallocConnRef(SSvrConn* conn); @@ -597,14 +597,14 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { tDebug("%s conn %p read error:%s", transLabel(pInst), conn, uv_err_name(nread)); if (nread < 0) { conn->broken = true; - if (conn->status == ConnAcquire) { - if (conn->regArg.init) { - tTrace("%s conn %p broken, notify server app", transLabel(pInst), conn); - STrans* pInst = conn->pInst; - (*pInst->cfp)(pInst->parent, &(conn->regArg.msg), NULL); - memset(&conn->regArg, 0, sizeof(conn->regArg)); - } - } + // if (conn->status == ConnAcquire) { + // if (conn->regArg.init) { + // tTrace("%s conn %p broken, notify server app", transLabel(pInst), conn); + // STrans* pInst = conn->pInst; + // (*pInst->cfp)(pInst->parent, &(conn->regArg.msg), NULL); + // memset(&conn->regArg, 0, sizeof(conn->regArg)); + // } + // } destroyConn(conn, true); } } @@ -916,40 +916,6 @@ static void uvShutDownCb(uv_shutdown_t* req, int status) { uv_close((uv_handle_t*)req->handle, uvDestroyConn); taosMemoryFree(req); } -// static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { -// if ((pHead)->release == 1 && (pHead->msgLen) == sizeof(*pHead)) { -// tTrace("conn %p received release request", pConn); -// STraceId traceId = pHead->traceId; -// (void)transClearBuffer(&pConn->readBuf); -// transFreeMsg(transContFromHead((char*)pHead)); -// if (pConn->status != ConnAcquire) { -// return true; -// } -// pConn->status = ConnRelease; - -// STransMsg tmsg = {.code = 0, -// .info.handle = (void*)pConn, -// .info.traceId = traceId, -// .info.ahandle = (void*)0x9527, -// .info.seqNum = htonl(pHead->seqNum)}; -// SSvrMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrMsg)); -// srvMsg->msg = tmsg; -// srvMsg->type = Release; -// srvMsg->pConn = pConn; -// if (!transQueuePush(&pConn->srvMsgs, srvMsg)) { -// return true; -// } -// if (pConn->regArg.init) { -// tTrace("conn %p release, notify server app", pConn); -// STrans* pInst = pConn->pInst; -// (*pInst->cfp)(pInst->parent, &(pConn->regArg.msg), NULL); -// memset(&pConn->regArg, 0, sizeof(pConn->regArg)); -// } -// uvStartSendRespImpl(srvMsg); -// return true; -// } -// return false; -// } static void uvWorkDoTask(uv_work_t* req) { // doing time-consumeing task // only auth conn currently, add more func later @@ -1233,7 +1199,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { TAOS_CHECK_GOTO(code, &lino, _end); } - memset(&pConn->regArg, 0, sizeof(pConn->regArg)); + // memset(&pConn->regArg, 0, sizeof(pConn->regArg)); pConn->broken = false; pConn->status = ConnNormal; @@ -1311,12 +1277,12 @@ static FORCE_INLINE void destroyConn(SSvrConn* conn, bool clear) { } } } -static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn) { - if (conn->regArg.init == 1) { - transFreeMsg(conn->regArg.msg.pCont); - conn->regArg.init = 0; - } -} +// static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn) { +// if (conn->regArg.init == 1) { +// transFreeMsg(conn->regArg.msg.pCont); +// conn->regArg.init = 0; +// } +// } static int32_t reallocConnRef(SSvrConn* conn) { if (conn->refId > 0) { (void)transReleaseExHandle(uvGetConnRefOfThrd(conn->hostThrd), conn->refId); @@ -1373,7 +1339,7 @@ static void uvDestroyConn(uv_handle_t* handle) { taosHashCleanup(conn->pQTable); taosMemoryFree(conn->pTcp); - destroyConnRegArg(conn); + // destroyConnRegArg(conn); (void)transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); From 56793dd89b28a6f1b467b58e14f7484ac4800b11 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 10 Sep 2024 10:54:04 +0800 Subject: [PATCH 061/240] opt transport --- source/libs/transport/inc/transComm.h | 1 - source/libs/transport/src/transCli.c | 2 +- source/libs/transport/src/transSvr.c | 22 ++++++++++------------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 451109cd59..7053c428e2 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -183,7 +183,6 @@ typedef struct { int32_t compatibilityVer; uint32_t magicNum; STraceId traceId; - uint64_t ahandle; // ahandle assigned by client int64_t qid; uint32_t code; // del later uint32_t msgType; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 712b278e31..7c09082e5b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1517,7 +1517,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { STransMsgHead* pHead = transHeadFromCont(pReq->pCont); if (pHead->comp == 0) { - pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; + // pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; pHead->persist = REQUEST_PERSIS_HANDLE(pReq) ? 1 : 0; pHead->msgType = pReq->msgType; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 97afc77b9a..1ce1cb0596 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -484,7 +484,7 @@ static bool uvHandleReq(SSvrConn* pConn) { tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); return false; } - pHead->ahandle = htole64(pHead->ahandle); + // pHead->ahandle = htole64(pHead->ahandle); pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); @@ -763,12 +763,16 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { if (pConn->broken) { return; } - queue sendReqNode; - QUEUE_INIT(&sendReqNode); + + SWriteReq* pWreq = taosMemoryCalloc(1, sizeof(SWriteReq)); + pWreq->conn = pConn; + QUEUE_INIT(&pWreq->q); + QUEUE_INIT(&pWreq->node); + pWreq->req.data = pWreq; uv_buf_t* pBuf = NULL; int32_t bufNum = 0; - code = uvBuildToSendData(pConn, &pBuf, &bufNum, &sendReqNode); + code = uvBuildToSendData(pConn, &pBuf, &bufNum, &pWreq->node); if (code != 0) { tError("%s conn %p failed to send data", transLabel(pConn->pInst), pConn); return; @@ -780,12 +784,6 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { transRefSrvHandle(pConn); - SWriteReq* pWreq = taosMemoryCalloc(1, sizeof(SWriteReq)); - pWreq->conn = pConn; - QUEUE_INIT(&pWreq->q); - QUEUE_MOVE(&sendReqNode, &pWreq->node); - pWreq->req.data = pWreq; - uv_write_t* req = &pWreq->req; if (req == NULL) { if (!uv_is_closing((uv_handle_t*)(pConn->pTcp))) { @@ -1711,7 +1709,7 @@ void transRefSrvHandle(void* handle) { } SSvrConn* pConn = handle; pConn->ref++; - tTrace("conn %p ref count:%d", handle, pConn->ref); + tTrace("conn %p ref count:%d", pConn, pConn->ref); } void transUnrefSrvHandle(void* handle) { @@ -1720,7 +1718,7 @@ void transUnrefSrvHandle(void* handle) { } SSvrConn* pConn = handle; pConn->ref--; - tTrace("conn %p ref count:%d", handle, pConn->ref); + tTrace("conn %p ref count:%d", pConn, pConn->ref); if (pConn->ref == 0) { destroyConn((SSvrConn*)handle, true); } From 60cb1cbf6be03aa87011f981be8e8084a30a4583 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 11 Sep 2024 08:23:02 +0800 Subject: [PATCH 062/240] opt transport --- source/libs/transport/inc/transComm.h | 16 +++- source/libs/transport/src/transComm.c | 125 ++++++++++++-------------- source/libs/transport/src/transSvr.c | 18 ++-- 3 files changed, 86 insertions(+), 73 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 7053c428e2..19322c1327 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -363,8 +363,9 @@ void transReqQueueClear(queue* q); // queue sending msgs typedef struct { - SArray* q; + queue node; void (*freeFunc)(const void* arg); + int32_t size; } STransQueue; /* @@ -377,7 +378,7 @@ int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)); * put arg into queue * if queue'size > 1, return false; else return true */ -bool transQueuePush(STransQueue* queue, void* arg); +int32_t transQueuePush(STransQueue* queue, void* arg); /* * the size of queue */ @@ -390,10 +391,21 @@ void* transQueuePop(STransQueue* queue); * get ith from queue */ void* transQueueGet(STransQueue* queue, int i); +/* + * head elm from queue + */ + +void* tranQueueHead(STransQueue* q); /* * rm ith from queue */ + void* transQueueRm(STransQueue* queue, int i); +/* + * remove el from queue + */ + +void transQueueRemove(STransQueue* q, void* e); /* * queue empty or not */ diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index add463bb45..19196106d3 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -437,82 +437,75 @@ void transReqQueueClear(queue* q) { } } -int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) { - queue->q = taosArrayInit(2, sizeof(void*)); - if (queue->q == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - queue->freeFunc = (void (*)(const void*))freeFunc; +int32_t transQueueInit(STransQueue* wq, void (*freeFunc)(const void* arg)) { + QUEUE_INIT(&wq->node); + wq->freeFunc = (void (*)(const void*))freeFunc; + wq->size = 0; + return 0; +} +int32_t transQueuePush(STransQueue* q, void* arg) { + queue* node = arg; + QUEUE_PUSH(&q->node, node); + q->size++; return 0; } -bool transQueuePush(STransQueue* queue, void* arg) { - if (queue->q == NULL) { - return true; - } - (void)taosArrayPush(queue->q, &arg); - if (taosArrayGetSize(queue->q) > 1) { - return false; - } - return true; -} -void* transQueuePop(STransQueue* queue) { - if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) { - return NULL; - } - void* ptr = taosArrayGetP(queue->q, 0); - taosArrayRemove(queue->q, 0); - return ptr; -} -int32_t transQueueSize(STransQueue* queue) { - if (queue->q == NULL) { - return 0; - } - return taosArrayGetSize(queue->q); -} -void* transQueueGet(STransQueue* queue, int i) { - if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) { - return NULL; - } - if (i >= taosArrayGetSize(queue->q)) { - return NULL; - } +void* transQueuePop(STransQueue* q) { + if (q->size == 0) return NULL; - void* ptr = taosArrayGetP(queue->q, i); - return ptr; + queue* tail = QUEUE_TAIL(&q->node); + QUEUE_REMOVE(tail); + return tail; +} +int32_t transQueueSize(STransQueue* q) { return q->size; } + +void* transQueueGet(STransQueue* q, int idx) { + if (q->size == 0) return NULL; + + while (idx-- > 0) { + queue* node = QUEUE_NEXT(&q->node); + if (node == &q->node) return NULL; + } + return NULL; } -void* transQueueRm(STransQueue* queue, int i) { - if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) { - return NULL; - } - if (i >= taosArrayGetSize(queue->q)) { - return NULL; - } - void* ptr = taosArrayGetP(queue->q, i); - taosArrayRemove(queue->q, i); - return ptr; +void* tranQueueHead(STransQueue* q) { + if (q->size == 0) return NULL; + + queue* head = QUEUE_HEAD(&q->node); + return head; } -bool transQueueEmpty(STransQueue* queue) { - if (queue->q == NULL) { - return true; +void* transQueueRm(STransQueue* q, int i) { + // if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) { + // return NULL; + // } + // if (i >= taosArrayGetSize(queue->q)) { + // return NULL; + // } + // void* ptr = taosArrayGetP(queue->q, i); + // taosArrayRemove(queue->q, i); + // return ptr; + return NULL; +} + +void transQueueRemove(STransQueue* q, void* e) { + queue* node = e; + QUEUE_REMOVE(node); + q->size--; +} + +bool transQueueEmpty(STransQueue* q) { return q->size == 0 ? true : false; } + +void transQueueClear(STransQueue* q) { + while (!QUEUE_IS_EMPTY(q->node)) { + queue* h = QUEUE_HEAD(&q->node); + QUEUE_REMOVE(h); + q->freeFunc(h); + q->size--; } - return taosArrayGetSize(queue->q) == 0; -} -void transQueueClear(STransQueue* queue) { - if (queue->freeFunc != NULL) { - for (int i = 0; i < taosArrayGetSize(queue->q); i++) { - void* p = taosArrayGetP(queue->q, i); - queue->freeFunc(p); - } - } - taosArrayClear(queue->q); -} -void transQueueDestroy(STransQueue* queue) { - transQueueClear(queue); - taosArrayDestroy(queue->q); } +void transQueueDestroy(STransQueue* q) { transQueueClear(q); } static FORCE_INLINE int32_t timeCompare(const HeapNode* a, const HeapNode* b) { SDelayTask* arg1 = container_of(a, SDelayTask, node); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 1ce1cb0596..51b0784f73 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -629,21 +629,30 @@ void uvOnSendCb(uv_write_t* req, int status) { SSvrConn* conn = userReq->conn; queue* src = &userReq->node; - tDebug("%s conn %p send data", transLabel(conn->pInst), conn); - + tDebug("%s conn %p send data out ", transLabel(conn->pInst), conn); if (status == 0) { while (!QUEUE_IS_EMPTY(src)) { queue* head = QUEUE_HEAD(&src); QUEUE_REMOVE(head); - SSvrMsg* smsg = QUEUE_DATA(head, SSvrMsg, sendReq); - + SSvrMsg* smsg = QUEUE_DATA(head, SSvrMsg, sendReq); STraceId* trace = &smsg->msg.info.traceId; tGDebug("%s conn %p msg already send out, seqNum:%d, qid:%ld", transLabel(conn->pInst), conn, smsg->msg.info.seqNum, smsg->msg.info.qId); destroySmsg(smsg); } } else { + while (!QUEUE_IS_EMPTY(src)) { + queue* head = QUEUE_HEAD(&src); + QUEUE_REMOVE(head); + + SSvrMsg* smsg = QUEUE_DATA(head, SSvrMsg, sendReq); + STraceId* trace = &smsg->msg.info.traceId; + tGDebug("%s conn %p failed to send, seqNum:%d, qid:%ld, reason:%s", transLabel(conn->pInst), conn, + smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); + destroySmsg(smsg); + } + if (!uv_is_closing((uv_handle_t*)(conn->pTcp))) { tError("conn %p failed to write data, %s", conn, uv_err_name(status)); conn->broken = true; @@ -766,7 +775,6 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { SWriteReq* pWreq = taosMemoryCalloc(1, sizeof(SWriteReq)); pWreq->conn = pConn; - QUEUE_INIT(&pWreq->q); QUEUE_INIT(&pWreq->node); pWreq->req.data = pWreq; From 65a5dad3cbd6632f59abd26b752488e8e0fc8715 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 11 Sep 2024 20:18:34 +0800 Subject: [PATCH 063/240] opt transport --- source/libs/transport/inc/transComm.h | 6 +- source/libs/transport/src/transCli.c | 364 ++++++-------------------- source/libs/transport/src/transComm.c | 24 +- source/libs/transport/src/transSvr.c | 140 +++++----- 4 files changed, 173 insertions(+), 361 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 19322c1327..6fd3e830ae 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -372,7 +372,7 @@ typedef struct { * init queue * note: queue'size is small, default 1 */ -int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)); +int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(void* arg)); /* * put arg into queue @@ -396,6 +396,10 @@ void* transQueueGet(STransQueue* queue, int i); */ void* tranQueueHead(STransQueue* q); +/* + * remove all match elm from queue + */ +void transQueueRemoveByFilter(STransQueue* q, bool (*filter)(void* e, void* arg), void* arg, void* dst, int32_t size); /* * rm ith from queue */ diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 7c09082e5b..63ef272533 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -65,7 +65,8 @@ typedef struct SCliConn { void* hostThrd; SConnBuffer readBuf; - STransQueue reqs; + STransQueue reqsToSend; + STransQueue reqsSentOut; SHashObj* pQueryTable; queue q; @@ -340,57 +341,8 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); #define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para)) #define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pInst))->label) -// #define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ -// do { \ -// int i = 0, sz = transQueueSize(&conn->reqs); \ -// for (; i < sz; i++) { \ -// pReq = transQueueGet(&conn->reqs, i); \ -// if (pReq->ctx != NULL && (uint64_t)pReq->ctx->ahandle == ahandle) { \ -// break; \ -// } \ -// } \ -// if (i == sz) { \ -// pReq = NULL; \ -// } else { \ -// pReq = transQueueRm(&conn->reqs, i); \ -// } \ -// } while (0) - -// #define CONN_GET_NEXT_SENDMSG(conn) \ -// do { \ -// int i = 0; \ -// do { \ -// pCliMsg = transQueueGet(&conn->reqs, i++); \ -// if (pCliMsg && 0 == pCliMsg->sent) { \ -// break; \ -// } \ -// } while (pCliMsg != NULL); \ -// if (pCliMsg == NULL) { \ -// goto _RETURN; \ -// } \ -// } while (0) - -// static int32_t cliConnFindToSendMsg(SCliConn* pConn, SCliReq** pReq) { -// int32_t code = 0; -// for (int32_t i = 0; i < transQueueSize(&pConn->reqs); i++) { -// SCliReq* p = transQueueGet(&pConn->reqs, i); -// if (p->sent == 0) { -// *pReq = p; -// return 0; -// } -// } -// return TSDB_CODE_OUT_OF_RANGE; -// } -// #define CONN_SET_PERSIST_BY_APP(conn) \ -// do { \ -// if (conn->status == ConnNormal) { \ -// conn->status = ConnAcquire; \ -// transRefCliHandle(conn); \ -// } \ -// } while (0) - -#define CONN_NO_PERSIST_BY_APP(conn) \ - (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && TRANS_CONN_REF_GET(conn) == 1) +// #define CONN_NO_PERSIST_BY_APP(conn) \ +// (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && TRANS_CONN_REF_GET(conn) == 1) // #define CONN_RELEASE_BY_SERVER(conn) \ // (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && TRANS_CONN_REF_GET(conn) == 1) @@ -412,64 +364,6 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); static void* cliWorkThread(void* arg); -// static void cliReleaseUnfinishedMsg(SCliConn* conn) { -// SCliThrd* pThrd = conn->hostThrd; - -// for (int i = 0; i < transQueueSize(&conn->reqs); i++) { -// SCliReq* msg = transQueueGet(&conn->reqs, i); -// if (msg != NULL && msg->ctx != NULL && msg->ctx->ahandle != (void*)0x9527) { -// if (conn->ctx.freeFunc != NULL && msg->ctx->ahandle != NULL) { -// conn->ctx.freeFunc(msg->ctx->ahandle); -// } else if (msg->msg.info.notFreeAhandle == 0 && msg->ctx->ahandle != NULL && pThrd->destroyAhandleFp != NULL) { -// tDebug("%s conn %p destroy unfinished ahandle %p", CONN_GET_INST_LABEL(conn), conn, msg->ctx->ahandle); -// pThrd->destroyAhandleFp(msg->ctx->ahandle); -// } -// } -// destroyReq(msg); -// } -// transQueueClear(&conn->reqs); -// memset(&conn->ctx, 0, sizeof(conn->ctx)); -// } -// bool cliMaySendCachedMsg(SCliConn* conn) { -// if (!transQueueEmpty(&conn->reqs)) { -// SCliReq* pCliMsg = NULL; -// CONN_GET_NEXT_SENDMSG(conn); -// (void)cliSend2(conn); -// return true; -// } -// return false; -// _RETURN: -// return false; -// } -// bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { -// if (refId == 0) return false; -// SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); -// if (exh == NULL) { -// tDebug("release conn %p, refId: %" PRId64 "", conn, refId); -// return false; -// } -// taosWLockLatch(&exh->latch); -// if (exh->handle == NULL) exh->handle = conn; -// exh->inited = 1; -// exh->pThrd = conn->hostThrd; -// if (!QUEUE_IS_EMPTY(&exh->q)) { -// queue* h = QUEUE_HEAD(&exh->q); -// QUEUE_REMOVE(h); -// taosWUnLockLatch(&exh->latch); -// SCliReq* t = QUEUE_DATA(h, SCliReq, seqq); -// transCtxMerge(&conn->ctx, &t->ctx->userCtx); -// (void)transQueuePush(&conn->reqs, t); -// tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); -// (void)transReleaseExHandle(transGetRefMgt(), refId); -// (void)cliSend2(conn); -// return true; -// } -// taosWUnLockLatch(&exh->latch); -// tDebug("empty conn %p, refId: %" PRId64 "", conn, refId); -// (void)transReleaseExHandle(transGetRefMgt(), refId); -// return false; -// } - int32_t cliGetConnTimer(SCliThrd* pThrd, SCliConn* pConn) { uv_timer_t* timer = taosArrayGetSize(pThrd->timerList) > 0 ? *(uv_timer_t**)taosArrayPop(pThrd->timerList) : NULL; if (timer == NULL) { @@ -501,10 +395,10 @@ void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { int32_t code = 0; - for (int i = 0; i < transQueueSize(&conn->reqs); i++) { - SCliReq* p = transQueueGet(&conn->reqs, i); + for (int i = 0; i < transQueueSize(&conn->reqsSentOut); i++) { + SCliReq* p = transQueueGet(&conn->reqsSentOut, i); if (p->seq == seq) { - transQueueRm(&conn->reqs, i); + transQueueRm(&conn->reqsSentOut, i); *pReq = p; return 0; } @@ -514,7 +408,8 @@ int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { int8_t cliMayRecycleConn(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; - if (transQueueSize(&conn->reqs) == 0 && taosHashGetSize(conn->pQTable) == 0) { + if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && + taosHashGetSize(conn->pQTable) == 0) { (void)delConnFromHeapCache(pThrd->connHeapCache, conn); addConnToPool(pThrd->pool, conn); return 1; @@ -522,6 +417,16 @@ int8_t cliMayRecycleConn(SCliConn* conn) { return 0; } +bool filterByQid(void* key, void* arg) { + int64_t* qid = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + + if (pReq->msg.info.qId == *qid) { + return true; + } else { + return false; + } +} int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHead) { pResp->contLen = transContLenFromMsg(pHead->msgLen); pResp->pCont = transContFromHead((char*)pHead); @@ -560,18 +465,22 @@ int32_t cliConnMayHandleState_releaseReq(SCliConn* conn, STransMsgHead* pHead) { tDebug("%s conn %p failed to release req %ld from thrd ", CONN_GET_INST_LABEL(conn), conn, qId); } - tDebug("%s %p req size:%d", CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqs)); - for (int32_t i = 0; i < transQueueSize(&conn->reqs); i++) { - SCliReq* pReq = transQueueGet(&conn->reqs, i); - if (pReq->msg.info.qId == qId) { - transQueueRm(&conn->reqs, i); + tDebug("%s %p reqToSend:%d, sentOut:%d", CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqsToSend), + transQueueSize(&conn->reqsSentOut)); - if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { - pThrd->destroyAhandleFp(pReq->ctx->ahandle); - } - destroyReq(pReq); - i--; + queue set; + QUEUE_INIT(&set); + transQueueRemoveByFilter(&conn->reqsSentOut, filterByQid, &qId, &set, -1); + transQueueRemoveByFilter(&conn->reqsToSend, filterByQid, &qId, &set, -1); + + while (!QUEUE_IS_EMPTY(&set)) { + queue* el = QUEUE_HEAD(&set); + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + QUEUE_REMOVE(el); + if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { + pThrd->destroyAhandleFp(pReq->ctx->ahandle); } + destroyReq(pReq); } taosMemoryFree(pHead); return 1; @@ -674,76 +583,7 @@ void cliHandleResp2(SCliConn* conn) { (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } -void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { - // if (transQueueEmpty(&pConn->reqs)) { - // if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) { - // tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn); - // if (TRANS_CONN_REF_GET(pConn) > 1) transUnrefCliHandle(pConn); - // transUnrefCliHandle(pConn); - // return; - // } - // } - // SCliThrd* pThrd = pConn->hostThrd; - // STrans* pInst = pThrd->pInst; - // bool once = false; - // do { - // SCliReq* pReq = transQueuePop(&pConn->reqs); - - // if (pReq == NULL && once) { - // break; - // } - - // if (pReq != NULL && REQUEST_NO_RESP(&pReq->msg)) { - // destroyReq(pReq); - // break; - // } - - // SReqCtx* pCtx = pReq ? pReq->ctx : NULL; - - // STransMsg transMsg = {0}; - // transMsg.code = code == -1 ? (pConn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; - // transMsg.msgType = pReq ? pReq->msg.msgType + 1 : 0; - // transMsg.info.ahandle = NULL; - // transMsg.info.cliVer = pInst->compatibilityVer; - - // if (pReq == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { - // transMsg.info.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType); - // tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle, - // TMSG_INFO(transMsg.msgType)); - // if (transMsg.info.ahandle == NULL) { - // int32_t msgType = 0; - // transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, &msgType); - // transMsg.msgType = msgType; - // tDebug("%s conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, - // transMsg.info.ahandle); - // } - // } else { - // transMsg.info.ahandle = (pReq != NULL && pReq->type != Release && pCtx) ? pCtx->ahandle : NULL; - // } - - // if (pCtx == NULL || pCtx->pSem == NULL) { - // if (transMsg.info.ahandle == NULL) { - // if (pReq == NULL || REQUEST_NO_RESP(&pReq->msg) || pReq->type == Release) { - // destroyReq(pReq); - // once = true; - // continue; - // } - // } - // } - - // if (pReq == NULL || (pReq && pReq->type != Release)) { - // int64_t refId = (pReq == NULL ? 0 : (int64_t)(pReq->msg.info.handle)); - // cliDestroyMsgInExhandle(refId); - // if (cliNotifyCb(pConn, pReq, &transMsg) != 0) { - // return; - // } - // } - // destroyReq(pReq); - // tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, TRANS_CONN_REF_GET(pConn)); - // } while (!transQueueEmpty(&pConn->reqs)); - // if (TRANS_CONN_REF_GET(pConn) > 1) transUnrefCliHandle(pConn); - // transUnrefCliHandle(pConn); -} +void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { return; } void cliHandleExcept(SCliConn* conn, int32_t code) { tTrace("%s conn %p except ref:%d", CONN_GET_INST_LABEL(conn), conn, TRANS_CONN_REF_GET(conn)); if (code != TSDB_CODE_RPC_FQDN_ERROR) { @@ -1068,22 +908,22 @@ static void addConnToPool(void* pool, SCliConn* conn) { SConnList* pList = conn->list; SMsgList* msgList = pList->list; - if (!QUEUE_IS_EMPTY(&msgList->msgQ)) { - queue* h = QUEUE_HEAD(&(msgList)->msgQ); - QUEUE_REMOVE(h); + // if (!QUEUE_IS_EMPTY(&msgList->msgQ)) { + // queue* h = QUEUE_HEAD(&(msgList)->msgQ); + // QUEUE_REMOVE(h); - SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); + // SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - transDQCancel(thrd->waitConnQueue, pReq->ctx->task); - pReq->ctx->task = NULL; + // transDQCancel(thrd->waitConnQueue, pReq->ctx->task); + // pReq->ctx->task = NULL; - transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); - (void)transQueuePush(&conn->reqs, pReq); + // transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); + // (void)transQueuePush(&conn->reqsToSend, pReq); - conn->status = ConnNormal; - (void)cliSend2(conn); - return; - } + // conn->status = ConnNormal; + // (void)cliSend2(conn); + // return; + // } conn->status = ConnInPool; QUEUE_PUSH(&conn->list->conns, &conn->q); @@ -1210,7 +1050,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } // static int32_t cliAddReqToConn(SCliConn* conn, SCliReq* pReq) { -// if (transQueuePush(&conn->reqs, pReq) != 0) { +// if (transQueuePush(&conn->reqsToSend, pReq) != 0) { // return TSDB_CODE_OUT_OF_MEMORY; // } // return 0; @@ -1218,7 +1058,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { // static int32_t cliRmReqFromConn(SCliConn* conn, SCliReq** pReq) { // // do nothing -// SCliReq* pTail = transQueuePop(&conn->reqs); +// SCliReq* pTail = transQueuePop(&conn->reqsToSend); // if (pTail == NULL) { // return TSDB_CODE_INVALID_PARA; // } @@ -1259,7 +1099,7 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) code = cliMayUpdateState(pThrd, pReq, pConn); addConnToHeapCache(pThrd->connHeapCache, pConn); - transQueuePush(&pConn->reqs, pReq); + transQueuePush(&pConn->reqsToSend, &pReq->q); return cliDoConn(pThrd, pConn); _exception: // free conn @@ -1289,7 +1129,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int transReqQueueInit(&conn->wreqQueue); - TAOS_CHECK_GOTO(transQueueInit(&conn->reqs, NULL), NULL, _failed); + TAOS_CHECK_GOTO(transQueueInit(&conn->reqsToSend, NULL), NULL, _failed); TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); @@ -1331,7 +1171,8 @@ _failed: destroyCliConnQTable(conn); taosHashCleanup(conn->pQTable); (void)transDestroyBuffer(&conn->readBuf); - transQueueDestroy(&conn->reqs); + transQueueDestroy(&conn->reqsToSend); + transQueueDestroy(&conn->reqsSentOut); taosMemoryFree(conn->dstAddr); (void)transReleaseExHandle(transGetRefMgt(), conn->refId); @@ -1417,8 +1258,9 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - while (!transQueueEmpty(&conn->reqs)) { - SCliReq* pReq = transQueuePop(&conn->reqs); + while (!transQueueEmpty(&conn->reqsToSend)) { + queue* el = transQueuePop(&conn->reqsToSend); + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); // ASSERT(pReq->type != Release); // ASSERT(REQUEST_NO_RESP(&pReq->msg) == 0); @@ -1446,25 +1288,17 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { } static void cliConnRmReqs(SCliConn* conn) { - for (int i = 0; i < transQueueSize(&conn->reqs); i++) { - SCliReq* pReq = transQueueGet(&conn->reqs, i); - if (pReq->sent == 1 && REQUEST_NO_RESP(&pReq->msg)) { - transQueueRm(&conn->reqs, i); - destroyReq(pReq); - i--; - } - } + // for (int i = 0; i < transQueueSize(&conn->reqsSentOut); i++) { + // SCliReq* pReq = transQueueGet(&conn->reqsSentOut, i); + // if (pReq->sent == 1 && REQUEST_NO_RESP(&pReq->msg)) { + // transQueueRm(&conn->reqsToSend, i); + // destroyReq(pReq); + // i--; + // } + // } + return; } -static int32_t cliShouldSendMsg(SCliConn* conn) { - for (int i = 0; i < transQueueSize(&conn->reqs); i++) { - SCliReq* pReq = transQueueGet(&conn->reqs, i); - if (pReq->sent == 0) { - return 1; - } - } - return 0; -} static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { SCliConn* conn = req->data; SCliThrd* pThrd = conn->hostThrd; @@ -1488,7 +1322,7 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { void cliSendBatch_shareConn(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - int32_t size = transQueueSize(&pConn->reqs); + int32_t size = transQueueSize(&pConn->reqsToSend); int32_t totalLen = 0; if (size == 0) { @@ -1498,11 +1332,9 @@ void cliSendBatch_shareConn(SCliConn* pConn) { uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); int j = 0; - for (int i = 0; i < size; i++) { - SCliReq* pCliMsg = transQueueGet(&pConn->reqs, i); - if (pCliMsg->sent == 1) { - continue; - } + while (!transQueueEmpty(&pConn->reqsToSend)) { + queue* h = transQueuePop(&pConn->reqsToSend); + SCliReq* pCliMsg = QUEUE_DATA(h, SCliReq, q); SReqCtx* pCtx = pCliMsg->ctx; pConn->seq++; @@ -1550,6 +1382,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { STraceId* trace = &pCliMsg->msg.info.traceId; tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d, qid:%ld", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); + transQueuePush(&pConn->reqsSentOut, pCliMsg->q); } if (j == 0) { taosMemoryFree(wb); @@ -1566,7 +1399,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; - transQueuePush(&pConn->reqs, pCliMsg); + transQueuePush(&pConn->reqsToSend, pCliMsg); if (pConn->connnected) { code = cliSend2(pConn); } else { @@ -1663,7 +1496,7 @@ _exception2: static void cliHandleFastFail_resp(SCliConn* pConn, int status) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - SCliReq* pReq = transQueueGet(&pConn->reqs, 0); + SCliReq* pReq = transQueueGet(&pConn->reqsToSend, 0); STraceId* trace = &pReq->msg.info.traceId; tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), @@ -1800,7 +1633,7 @@ static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { if (TRANS_CONN_REF_GET(conn) == 2) { transUnrefCliHandle(conn); - if (!transQueuePush(&conn->reqs, pReq)) { + if (!transQueuePush(&conn->reqsToSend, pReq)) { return; } (void)cliSend2(conn); @@ -1809,48 +1642,7 @@ static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { destroyReq(pReq); } } -static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { - SReqCtx* pCtx = pReq->ctx; - pThrd->cvtAddr = pCtx->cvtAddr; - destroyReq(pReq); -} -static void cliHandleFreeById(SCliThrd* pThrd, SCliReq* pReq) { - int32_t code = 0; - int64_t refId = (int64_t)(pReq->msg.info.handle); - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh == NULL) { - tDebug("id %" PRId64 " already released", refId); - destroyReq(pReq); - return; - } - - taosRLockLatch(&exh->latch); - SCliConn* conn = exh->handle; - taosRUnLockLatch(&exh->latch); - - if (conn == NULL || conn->refId != refId) { - TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); - } - tDebug("do free conn %p by id %" PRId64 "", conn, refId); - - int32_t size = transQueueSize(&conn->reqs); - if (size == 0) { - // already recv, and notify upper layer - TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); - } else { - while (TRANS_CONN_REF_GET(conn) >= 1) { - transUnrefCliHandle(conn); - } - return; - } -_exception: - tDebug("already free conn %p by id %" PRId64 "", conn, refId); - - (void)transReleaseExHandle(transGetRefMgt(), refId); - (void)transReleaseExHandle(transGetRefMgt(), refId); - (void)transRemoveExHandle(transGetRefMgt(), refId); - destroyReq(pReq); -} +static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { return; } SCliConn* cliGetConn(SCliReq** pReq, SCliThrd* pThrd, bool* ignore, char* addr) { SReqCtx* pCtx = (*pReq)->ctx; @@ -2322,9 +2114,9 @@ void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { transCtxCleanup(&conn->ctx); // cliReleaseUnfinishedMsg(conn); if (destroy == 1) { - transQueueDestroy(&conn->reqs); + transQueueDestroy(&conn->reqsToSend); } else { - transQueueClear(&conn->reqs); + transQueueClear(&conn->reqsToSend); } } @@ -2332,8 +2124,8 @@ void cliConnFreeMsgs(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - for (int i = 0; i < transQueueSize(&conn->reqs); i++) { - SCliReq* cmsg = transQueueGet(&conn->reqs, i); + for (int i = 0; i < transQueueSize(&conn->reqsToSend); i++) { + SCliReq* cmsg = transQueueGet(&conn->reqsToSend, i); if (cmsg->type == Release || REQUEST_NO_RESP(&cmsg->msg) || cmsg->msg.msgType == TDMT_SCH_DROP_TASK) { continue; } @@ -3697,7 +3489,7 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { SCliConn* args1 = container_of(a, SCliConn, node); SCliConn* args2 = container_of(b, SCliConn, node); - if (transQueueSize(&args1->reqs) > transQueueSize(&args2->reqs)) { + if (transQueueSize(&args1->reqsToSend) > transQueueSize(&args2->reqsToSend)) { return 0; } return 1; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 19196106d3..64ca99ad46 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -437,7 +437,7 @@ void transReqQueueClear(queue* q) { } } -int32_t transQueueInit(STransQueue* wq, void (*freeFunc)(const void* arg)) { +int32_t transQueueInit(STransQueue* wq, void (*freeFunc)(void* arg)) { QUEUE_INIT(&wq->node); wq->freeFunc = (void (*)(const void*))freeFunc; wq->size = 0; @@ -453,7 +453,7 @@ int32_t transQueuePush(STransQueue* q, void* arg) { void* transQueuePop(STransQueue* q) { if (q->size == 0) return NULL; - queue* tail = QUEUE_TAIL(&q->node); + queue* tail = QUEUE_HEAD(&q->node); QUEUE_REMOVE(tail); return tail; } @@ -469,6 +469,23 @@ void* transQueueGet(STransQueue* q, int idx) { return NULL; } +void transQueueRemoveByFilter(STransQueue* q, bool (*filter)(void* e, void* arg), void* arg, void* dst, int32_t size) { + queue* d = dst; + queue* node = QUEUE_NEXT(&q->node); + while (node != &q->node) { + queue* next = QUEUE_NEXT(node); + if (filter(node, arg)) { + QUEUE_REMOVE(node); + q->size--; + QUEUE_PUSH(d, node); + if (--size == 0) { + break; + } + } + node = next; + } +} + void* tranQueueHead(STransQueue* q) { if (q->size == 0) return NULL; @@ -490,6 +507,7 @@ void* transQueueRm(STransQueue* q, int i) { } void transQueueRemove(STransQueue* q, void* e) { + if (q->size == 0) return; queue* node = e; QUEUE_REMOVE(node); q->size--; @@ -501,7 +519,7 @@ void transQueueClear(STransQueue* q) { while (!QUEUE_IS_EMPTY(q->node)) { queue* h = QUEUE_HEAD(&q->node); QUEUE_REMOVE(h); - q->freeFunc(h); + if (q->freeFunc != NULL) (q->freeFunc)(h); q->size--; } } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 51b0784f73..fcaf82a824 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -36,7 +36,7 @@ typedef struct SSvrConn { void* pInst; // rpc init void* ahandle; // void* hostThrd; - STransQueue srvMsgs; + STransQueue resps; // SSvrRegArg regArg; bool broken; // conn broken; @@ -63,7 +63,7 @@ typedef struct SSvrConn { SHashObj* pQTable; } SSvrConn; -typedef struct SSvrMsg { +typedef struct SSvrRespMsg { SSvrConn* pConn; STransMsg msg; queue q; @@ -73,9 +73,7 @@ typedef struct SSvrMsg { FilteFunc func; int8_t sent; - queue sendReq; - -} SSvrMsg; +} SSvrRespMsg; typedef struct { int64_t ver; @@ -158,14 +156,14 @@ static void uvWorkAfterTask(uv_work_t* req, int status); static void uvWalkCb(uv_handle_t* handle, void* arg); static void uvFreeCb(uv_handle_t* handle); -static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg); +static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg); -static int uvPrepareSendData(SSvrMsg* msg, uv_buf_t* wb); -static void uvStartSendResp(SSvrMsg* msg); +static int uvPrepareSendData(SSvrRespMsg* msg, uv_buf_t* wb); +static void uvStartSendResp(SSvrRespMsg* msg); static void uvNotifyLinkBrokenToApp(SSvrConn* conn); -static FORCE_INLINE void destroySmsg(SSvrMsg* smsg); +static FORCE_INLINE void destroySmsg(SSvrRespMsg* smsg); 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); @@ -174,13 +172,13 @@ static int32_t reallocConnRef(SSvrConn* conn); int32_t uvGetConnRefOfThrd(SWorkThrd* thrd) { return thrd ? thrd->connRefMgt : -1; } -static void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd); -static void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd); -static void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd); -static void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd); -static void uvHandleUpdate(SSvrMsg* pMsg, SWorkThrd* thrd); -static void (*transAsyncHandle[])(SSvrMsg* msg, SWorkThrd* thrd) = {uvHandleResp, uvHandleQuit, uvHandleRelease, - uvHandleRegister, uvHandleUpdate}; +static void uvHandleQuit(SSvrRespMsg* msg, SWorkThrd* thrd); +static void uvHandleRelease(SSvrRespMsg* msg, SWorkThrd* thrd); +static void uvHandleResp(SSvrRespMsg* msg, SWorkThrd* thrd); +static void uvHandleRegister(SSvrRespMsg* msg, SWorkThrd* thrd); +static void uvHandleUpdate(SSvrRespMsg* pMsg, SWorkThrd* thrd); +static void (*transAsyncHandle[])(SSvrRespMsg* msg, SWorkThrd* thrd) = {uvHandleResp, uvHandleQuit, uvHandleRelease, + uvHandleRegister, uvHandleUpdate}; static void uvDestroyConn(uv_handle_t* handle); @@ -447,17 +445,17 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { (void)taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); } - STransMsg tmsg = {.code = code, - .msgType = pHead->msgType + 1, - .info.qId = qId, - .info.traceId = pHead->traceId, - .info.seqNum = htonl(pHead->seqNum)}; - SSvrMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrMsg)); + STransMsg tmsg = {.code = code, + .msgType = pHead->msgType + 1, + .info.qId = qId, + .info.traceId = pHead->traceId, + .info.seqNum = htonl(pHead->seqNum)}; + SSvrRespMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); srvMsg->msg = tmsg; srvMsg->type = Normal; srvMsg->pConn = pConn; - transQueuePush(&pConn->srvMsgs, srvMsg); + transQueuePush(&pConn->resps, &srvMsg->q); uvStartSendRespImpl(srvMsg); return 1; @@ -635,8 +633,8 @@ void uvOnSendCb(uv_write_t* req, int status) { queue* head = QUEUE_HEAD(&src); QUEUE_REMOVE(head); - SSvrMsg* smsg = QUEUE_DATA(head, SSvrMsg, sendReq); - STraceId* trace = &smsg->msg.info.traceId; + SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); + STraceId* trace = &smsg->msg.info.traceId; tGDebug("%s conn %p msg already send out, seqNum:%d, qid:%ld", transLabel(conn->pInst), conn, smsg->msg.info.seqNum, smsg->msg.info.qId); destroySmsg(smsg); @@ -646,8 +644,8 @@ void uvOnSendCb(uv_write_t* req, int status) { queue* head = QUEUE_HEAD(&src); QUEUE_REMOVE(head); - SSvrMsg* smsg = QUEUE_DATA(head, SSvrMsg, sendReq); - STraceId* trace = &smsg->msg.info.traceId; + SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); + STraceId* trace = &smsg->msg.info.traceId; tGDebug("%s conn %p failed to send, seqNum:%d, qid:%ld, reason:%s", transLabel(conn->pInst), conn, smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); destroySmsg(smsg); @@ -676,7 +674,7 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) { taosMemoryFree(req); } -static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { +static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { SSvrConn* pConn = smsg->pConn; STransMsg* pMsg = &smsg->msg; if (pMsg->pCont == 0) { @@ -699,7 +697,7 @@ 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) { ASSERT(0); - // (void)transQueuePop(&pConn->srvMsgs); + // (void)transQueuePop(&pConn->resps); // destroySmsg(smsg); // return TSDB_CODE_INVALID_MSG; } @@ -728,30 +726,27 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { wb->len = len; return 0; } -static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* bufNum, queue* sendReqNode) { +static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* bufNum, queue* toSendQ) { + int32_t size = transQueueSize(&pConn->resps); + tDebug("%s conn %p has %d msg to send", transLabel(pConn->pInst), pConn, size); + if (size == 0) { + return 0; + } int32_t count = 0; - int32_t size = transQueueSize(&pConn->srvMsgs); uv_buf_t* pWb = taosMemoryCalloc(size, sizeof(uv_buf_t)); if (pWb == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - tDebug("%s conn %p has %d msg to send", transLabel(pConn->pInst), pConn, size); - for (int32_t i = 0; i < transQueueSize(&pConn->srvMsgs); i++) { - SSvrMsg* pMsg = transQueueGet(&pConn->srvMsgs, i); - if (pMsg->sent == 1) { - continue; - } - uv_buf_t wb; + while (transQueueSize(&pConn->resps) > 0) { + queue* el = transQueuePop(&pConn->resps); + SSvrRespMsg* pMsg = QUEUE_DATA(el, SSvrRespMsg, q); + uv_buf_t wb; (void)uvPrepareSendData(pMsg, &wb); pWb[count] = wb; pMsg->sent = 1; - - QUEUE_PUSH(sendReqNode, &pMsg->sendReq); - - transQueueRm(&pConn->srvMsgs, i); - i--; + QUEUE_PUSH(toSendQ, &pMsg->q); count++; } @@ -766,7 +761,7 @@ static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* buf return 0; } -static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { +static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { int32_t code = 0; SSvrConn* pConn = smsg->pConn; if (pConn->broken) { @@ -804,7 +799,7 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { (void)uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); taosMemoryFree(pBuf); } -int32_t uvMayHandleReleaseResp(SSvrMsg* pMsg) { +int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { SSvrConn* pConn = pMsg->pConn; int64_t qid = pMsg->msg.info.qId; if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE && qid > 0) { @@ -819,7 +814,7 @@ int32_t uvMayHandleReleaseResp(SSvrMsg* pMsg) { } return 0; } -static void uvStartSendResp(SSvrMsg* smsg) { +static void uvStartSendResp(SSvrRespMsg* smsg) { // impl SSvrConn* pConn = smsg->pConn; if (uvMayHandleReleaseResp(smsg) == TSDB_CODE_RPC_NO_STATE) { @@ -827,19 +822,19 @@ static void uvStartSendResp(SSvrMsg* smsg) { return; } - transQueuePush(&pConn->srvMsgs, smsg); + transQueuePush(&pConn->resps, &smsg->q); uvStartSendRespImpl(smsg); return; } -static FORCE_INLINE void destroySmsg(SSvrMsg* smsg) { +static FORCE_INLINE void destroySmsg(SSvrRespMsg* smsg) { if (smsg == NULL) { return; } transFreeMsg(smsg->msg.pCont); taosMemoryFree(smsg); } -static FORCE_INLINE void destroySmsgWrapper(void* smsg, void* param) { destroySmsg((SSvrMsg*)smsg); } +static FORCE_INLINE void destroySmsgWrapper(void* smsg, void* param) { destroySmsg((SSvrRespMsg*)smsg); } static void destroyAllConn(SWorkThrd* pThrd) { tTrace("thread %p destroy all conn ", pThrd); @@ -870,7 +865,7 @@ void uvWorkerAsyncCb(uv_async_t* handle) { queue* head = QUEUE_HEAD(&wq); QUEUE_REMOVE(head); - SSvrMsg* msg = QUEUE_DATA(head, SSvrMsg, q); + SSvrRespMsg* msg = QUEUE_DATA(head, SSvrRespMsg, q); if (msg == NULL) { tError("unexcept occurred, continue"); continue; @@ -1183,7 +1178,10 @@ void* transWorkerThread(void* arg) { return NULL; } - +void uvDestroyResp(void* e) { + SSvrRespMsg* pMsg = QUEUE_DATA(e, SSvrRespMsg, q); + destroySmsg(pMsg); +} static FORCE_INLINE SSvrConn* createConn(void* hThrd) { int32_t code = 0; SWorkThrd* pThrd = hThrd; @@ -1197,7 +1195,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { transReqQueueInit(&pConn->wreqQueue); QUEUE_INIT(&pConn->queue); - if ((code = transQueueInit(&pConn->srvMsgs, NULL)) != 0) { + if ((code = transQueueInit(&pConn->resps, uvDestroyResp)) != 0) { TAOS_CHECK_GOTO(code, &lino, _end); } @@ -1260,7 +1258,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { return pConn; _end: if (pConn) { - transQueueDestroy(&pConn->srvMsgs); + transQueueDestroy(&pConn->resps); (void)transDestroyBuffer(&pConn->readBuf); taosHashCleanup(pConn->pQTable); taosMemoryFree(pConn->pTcp); @@ -1334,11 +1332,11 @@ static void uvDestroyConn(uv_handle_t* handle) { STrans* pInst = thrd->pInst; tDebug("%s conn %p destroy", transLabel(pInst), conn); - for (int i = 0; i < transQueueSize(&conn->srvMsgs); i++) { - SSvrMsg* msg = transQueueGet(&conn->srvMsgs, i); - destroySmsg(msg); - } - transQueueDestroy(&conn->srvMsgs); + // for (int i = 0; i < transQueueSize(&conn->resps); i++) { + // SSvrRespMsg* msg = transQueueGet(&conn->resps, i); + // destroySmsg(msg); + // } + transQueueDestroy(&conn->resps); transReqQueueClear(&conn->wreqQueue); QUEUE_REMOVE(&conn->queue); @@ -1566,7 +1564,7 @@ End: return NULL; } -void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd) { +void uvHandleQuit(SSvrRespMsg* msg, SWorkThrd* thrd) { thrd->quit = true; if (QUEUE_IS_EMPTY(&thrd->conn)) { uv_walk(thrd->loop, uvWalkCb, NULL); @@ -1575,12 +1573,12 @@ void uvHandleQuit(SSvrMsg* msg, SWorkThrd* thrd) { } taosMemoryFree(msg); } -void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd) { +void uvHandleRelease(SSvrRespMsg* msg, SWorkThrd* thrd) { ASSERT(0); // int32_t code = 0; // SSvrConn* conn = msg->pConn; // if (conn->status == ConnAcquire) { - // if (!transQueuePush(&conn->srvMsgs, msg)) { + // if (!transQueuePush(&conn->resps, msg)) { // return; // } // uvStartSendRespImpl(msg); @@ -1591,13 +1589,13 @@ void uvHandleRelease(SSvrMsg* msg, SWorkThrd* thrd) { // destroySmsg(msg); } -void uvHandleResp(SSvrMsg* msg, SWorkThrd* thrd) { +void uvHandleResp(SSvrRespMsg* msg, SWorkThrd* thrd) { // send msg to client tDebug("%s conn %p start to send resp (2/2)", transLabel(thrd->pInst), msg->pConn); uvStartSendResp(msg); } -int32_t uvHandleStateReq(SSvrMsg* msg) { +int32_t uvHandleStateReq(SSvrRespMsg* msg) { int32_t code = 0; SSvrConn* conn = msg->pConn; tDebug("%s conn %p start to register brokenlink callback, qid:%" PRId64 "", transLabel(conn->pInst), conn, @@ -1613,14 +1611,14 @@ int32_t uvHandleStateReq(SSvrMsg* msg) { if (code == 0) tDebug("conn %p register brokenlink callback succ", conn); return code; } -void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd) { +void uvHandleRegister(SSvrRespMsg* msg, SWorkThrd* thrd) { SSvrConn* conn = msg->pConn; tDebug("%s conn %p register brokenlink callback", transLabel(thrd->pInst), conn); int32_t code = uvHandleStateReq(msg); taosMemoryFree(msg); } -void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) { +void uvHandleUpdate(SSvrRespMsg* msg, SWorkThrd* thrd) { SUpdateIpWhite* req = msg->arg; if (req == NULL) { tDebug("ip-white-list disable on trans"); @@ -1665,7 +1663,7 @@ void destroyWorkThrd(SWorkThrd* pThrd) { } (void)taosThreadJoin(pThrd->thread, NULL); SRV_RELEASE_UV(pThrd->loop); - TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrMsg, destroySmsgWrapper, NULL); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrRespMsg, destroySmsgWrapper, NULL); transAsyncPoolDestroy(pThrd->asyncPool); uvWhiteListDestroy(pThrd->pWhiteList); @@ -1675,7 +1673,7 @@ void destroyWorkThrd(SWorkThrd* pThrd) { taosMemoryFree(pThrd); } void sendQuitToWorkThrd(SWorkThrd* pThrd) { - SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* msg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); msg->type = Quit; tDebug("server send quit msg to work thread"); (void)transAsyncSend(pThrd->asyncPool, &msg->q); @@ -1752,7 +1750,7 @@ int32_t transReleaseSrvHandle(void* handle) { .info.qId = qId, .info.traceId = info->traceId}; - SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* m = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (m == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _return1; @@ -1803,7 +1801,7 @@ int32_t transSendResponse(const STransMsg* msg) { SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); - SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* m = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (m == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _return1; @@ -1851,7 +1849,7 @@ int32_t transRegisterMsg(const STransMsg* msg) { SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); - SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* m = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (m == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _return1; @@ -1895,7 +1893,7 @@ int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { for (int i = 0; i < svrObj->numOfThreads; i++) { SWorkThrd* pThrd = svrObj->pThreadObj[i]; - SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); + SSvrRespMsg* msg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (msg == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; break; From 13b1e5ee4ec5c460199bb6743195335192de12b3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 11 Sep 2024 22:17:38 +0800 Subject: [PATCH 064/240] opt parameter --- source/libs/transport/inc/transComm.h | 6 +- source/libs/transport/src/transCli.c | 164 ++++++++++++++++---------- source/libs/transport/src/transComm.c | 17 +-- 3 files changed, 113 insertions(+), 74 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 6fd3e830ae..dabed050ec 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -94,6 +94,10 @@ typedef void* queue[2]; /* Return the structure holding the given element. */ #define QUEUE_DATA(e, type, field) ((type*)((void*)((char*)(e)-offsetof(type, field)))) +typedef struct { + queue q; +} queueWrapper; + // #define TRANS_RETRY_COUNT_LIMIT 100 // retry count limit // #define TRANS_RETRY_INTERVAL 15 // retry interval (ms) #define TRANS_CONN_TIMEOUT 3000 // connect timeout (ms) @@ -364,7 +368,7 @@ void transReqQueueClear(queue* q); // queue sending msgs typedef struct { queue node; - void (*freeFunc)(const void* arg); + void (*freeFunc)(void* arg); int32_t size; } STransQueue; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 63ef272533..d5ec6e7e33 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -274,7 +274,7 @@ static void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq); static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq); static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq); static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq); -static void cliHandleFreeById(SCliThrd* pThrd, SCliReq* pReq); +static void cliHandleFreeById(SCliThrd* pThrd, SCliReq* pReq) { return; } static void cliDoReq(queue* h, SCliThrd* pThrd); static void cliDoBatchReq(queue* h, SCliThrd* pThrd); @@ -393,17 +393,30 @@ void cliResetConnTimer(SCliConn* conn) { void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } -int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { - int32_t code = 0; - for (int i = 0; i < transQueueSize(&conn->reqsSentOut); i++) { - SCliReq* p = transQueueGet(&conn->reqsSentOut, i); - if (p->seq == seq) { - transQueueRm(&conn->reqsSentOut, i); - *pReq = p; - return 0; - } +bool filteBySeq(void* key, void* arg) { + int32_t* seq = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->seq == *seq) { + return true; + } else { + return false; } - return TSDB_CODE_OUT_OF_RANGE; +} +int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { + int32_t code = 0; + queueWrapper set; + QUEUE_INIT(&set.q) + transQueueRemoveByFilter(&conn->reqsSentOut, filteBySeq, &seq, &set, 1); + + if (QUEUE_IS_EMPTY(&set.q)) { + return TSDB_CODE_OUT_OF_RANGE; + } + + queue* e = QUEUE_HEAD(&set.q); + SCliReq* p = QUEUE_DATA(e, SCliReq, q); + + *pReq = p; + return 0; } int8_t cliMayRecycleConn(SCliConn* conn) { @@ -468,13 +481,13 @@ int32_t cliConnMayHandleState_releaseReq(SCliConn* conn, STransMsgHead* pHead) { tDebug("%s %p reqToSend:%d, sentOut:%d", CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqsToSend), transQueueSize(&conn->reqsSentOut)); - queue set; - QUEUE_INIT(&set); + queueWrapper set; + QUEUE_INIT(&set.q); transQueueRemoveByFilter(&conn->reqsSentOut, filterByQid, &qId, &set, -1); transQueueRemoveByFilter(&conn->reqsToSend, filterByQid, &qId, &set, -1); - while (!QUEUE_IS_EMPTY(&set)) { - queue* el = QUEUE_HEAD(&set); + while (!QUEUE_IS_EMPTY(&set.q)) { + queue* el = QUEUE_HEAD(&set.q); SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); QUEUE_REMOVE(el); if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { @@ -1105,7 +1118,14 @@ _exception: // free conn return code; } - +void cliDestroyMsg(void* arg) { + queue* e = arg; + SCliReq* pReq = QUEUE_DATA(e, SCliReq, q); + if (pReq->msg.info.notFreeAhandle == 0) { + taosMemoryFree(pReq->ctx->ahandle); + } + destroyReq(pReq); +} static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int32_t port) { int32_t code = 0; int32_t lino = 0; @@ -1129,7 +1149,8 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int transReqQueueInit(&conn->wreqQueue); - TAOS_CHECK_GOTO(transQueueInit(&conn->reqsToSend, NULL), NULL, _failed); + TAOS_CHECK_GOTO(transQueueInit(&conn->reqsToSend, cliDestroyMsg), NULL, _failed); + TAOS_CHECK_GOTO(transQueueInit(&conn->reqsSentOut, cliDestroyMsg), NULL, _failed); TAOS_CHECK_GOTO(transInitBuffer(&conn->readBuf), NULL, _failed); @@ -1287,15 +1308,25 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { transUnrefCliHandle(conn); } +bool fileToRmReq(void* h, void* arg) { + queue* el = h; + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + if (pReq->sent == 1 && REQUEST_NO_RESP(&pReq->msg)) { + return true; + } + return false; +} static void cliConnRmReqs(SCliConn* conn) { - // for (int i = 0; i < transQueueSize(&conn->reqsSentOut); i++) { - // SCliReq* pReq = transQueueGet(&conn->reqsSentOut, i); - // if (pReq->sent == 1 && REQUEST_NO_RESP(&pReq->msg)) { - // transQueueRm(&conn->reqsToSend, i); - // destroyReq(pReq); - // i--; - // } - // } + queueWrapper set; + QUEUE_INIT(&set.q); + + transQueueRemoveByFilter(&conn->reqsSentOut, fileToRmReq, NULL, &set, -1); + while (!QUEUE_IS_EMPTY(&set.q)) { + queue* el = QUEUE_HEAD(&set.q); + QUEUE_REMOVE(el); + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + destroyReq(pReq); + } return; } @@ -1382,7 +1413,8 @@ void cliSendBatch_shareConn(SCliConn* pConn) { STraceId* trace = &pCliMsg->msg.info.traceId; tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d, qid:%ld", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); - transQueuePush(&pConn->reqsSentOut, pCliMsg->q); + + transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); } if (j == 0) { taosMemoryFree(wb); @@ -1399,7 +1431,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; - transQueuePush(&pConn->reqsToSend, pCliMsg); + transQueuePush(&pConn->reqsToSend, &pCliMsg->q); if (pConn->connnected) { code = cliSend2(pConn); } else { @@ -1496,11 +1528,11 @@ _exception2: static void cliHandleFastFail_resp(SCliConn* pConn, int status) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - SCliReq* pReq = transQueueGet(&pConn->reqsToSend, 0); + // //kSCliReq* pReq = transQueueGet(&pConn->reqsToSend, 0); - STraceId* trace = &pReq->msg.info.traceId; - tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), - TMSG_INFO(pReq->msg.msgType), pConn, pConn->dstAddr, uv_strerror(status)); + // STraceId* trace = &pReq->msg.info.traceId; + // tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), + // TMSG_INFO(pReq->msg.msgType), pConn, pConn->dstAddr, uv_strerror(status)); } static void cliHandleFastFail_noresp(SCliConn* pConn, int status) { @@ -1616,31 +1648,32 @@ static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq) { (void)uv_walk(pThrd->loop, cliWalkCb, NULL); } static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { - int64_t refId = (int64_t)(pReq->msg.info.handle); - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh == NULL) { - tDebug("%" PRId64 " already released", refId); - destroyReq(pReq); - return; - } + return; + // int64_t refId = (int64_t)(pReq->msg.info.handle); + // SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); + // if (exh == NULL) { + // tDebug("%" PRId64 " already released", refId); + // destroyReq(pReq); + // return; + // } - taosRLockLatch(&exh->latch); - SCliConn* conn = exh->handle; - taosRUnLockLatch(&exh->latch); + // taosRLockLatch(&exh->latch); + // SCliConn* conn = exh->handle; + // taosRUnLockLatch(&exh->latch); - (void)transReleaseExHandle(transGetRefMgt(), refId); - tDebug("%s conn %p start to release to inst", CONN_GET_INST_LABEL(conn), conn); + // (void)transReleaseExHandle(transGetRefMgt(), refId); + // tDebug("%s conn %p start to release to inst", CONN_GET_INST_LABEL(conn), conn); - if (TRANS_CONN_REF_GET(conn) == 2) { - transUnrefCliHandle(conn); - if (!transQueuePush(&conn->reqsToSend, pReq)) { - return; - } - (void)cliSend2(conn); - } else { - tError("%s conn %p already released", CONN_GET_INST_LABEL(conn), conn); - destroyReq(pReq); - } + // if (TRANS_CONN_REF_GET(conn) == 2) { + // transUnrefCliHandle(conn); + // if (!transQueuePush(&conn->reqsToSend, &pReq->q)) { + // return; + // } + // (void)cliSend2(conn); + // } else { + // tError("%s conn %p already released", CONN_GET_INST_LABEL(conn), conn); + // destroyReq(pReq); + // } } static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { return; } @@ -2111,31 +2144,32 @@ static void cliAsyncCb(uv_async_t* handle) { } void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { - transCtxCleanup(&conn->ctx); - // cliReleaseUnfinishedMsg(conn); + // transCtxCleanup(&conn->ctx); + // cliReleaseUnfinishedMsg(conn); if (destroy == 1) { transQueueDestroy(&conn->reqsToSend); } else { transQueueClear(&conn->reqsToSend); } + transQueueDestroy(&conn->reqsSentOut); } void cliConnFreeMsgs(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - for (int i = 0; i < transQueueSize(&conn->reqsToSend); i++) { - SCliReq* cmsg = transQueueGet(&conn->reqsToSend, i); - if (cmsg->type == Release || REQUEST_NO_RESP(&cmsg->msg) || cmsg->msg.msgType == TDMT_SCH_DROP_TASK) { - continue; - } + // for (int i = 0; i < transQueueSize(&conn->reqsToSend); i++) { + // SCliReq* cmsg = transQueueGet(&conn->reqsToSend, i); + // if (cmsg->type == Release || REQUEST_NO_RESP(&cmsg->msg) || cmsg->msg.msgType == TDMT_SCH_DROP_TASK) { + // continue; + // } - if (cliBuildExceptRespAndNotifyCb(pThrd, cmsg, 0) != 0) { - continue; - } + // if (cliBuildExceptRespAndNotifyCb(pThrd, cmsg, 0) != 0) { + // continue; + // } - cmsg->ctx->ahandle = NULL; - } + // cmsg->ctx->ahandle = NULL; + // } } static FORCE_INLINE void destroyReq(void* arg) { diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 64ca99ad46..e85ce2091a 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -439,7 +439,7 @@ void transReqQueueClear(queue* q) { int32_t transQueueInit(STransQueue* wq, void (*freeFunc)(void* arg)) { QUEUE_INIT(&wq->node); - wq->freeFunc = (void (*)(const void*))freeFunc; + wq->freeFunc = (void (*)(void*))freeFunc; wq->size = 0; return 0; } @@ -453,9 +453,10 @@ int32_t transQueuePush(STransQueue* q, void* arg) { void* transQueuePop(STransQueue* q) { if (q->size == 0) return NULL; - queue* tail = QUEUE_HEAD(&q->node); - QUEUE_REMOVE(tail); - return tail; + queue* head = QUEUE_HEAD(&q->node); + QUEUE_REMOVE(head); + q->size--; + return head; } int32_t transQueueSize(STransQueue* q) { return q->size; } @@ -470,14 +471,14 @@ void* transQueueGet(STransQueue* q, int idx) { } void transQueueRemoveByFilter(STransQueue* q, bool (*filter)(void* e, void* arg), void* arg, void* dst, int32_t size) { - queue* d = dst; - queue* node = QUEUE_NEXT(&q->node); + queueWrapper* d = dst; + queue* node = QUEUE_NEXT(&q->node); while (node != &q->node) { queue* next = QUEUE_NEXT(node); if (filter(node, arg)) { QUEUE_REMOVE(node); q->size--; - QUEUE_PUSH(d, node); + QUEUE_PUSH(&d->q, node); if (--size == 0) { break; } @@ -516,7 +517,7 @@ void transQueueRemove(STransQueue* q, void* e) { bool transQueueEmpty(STransQueue* q) { return q->size == 0 ? true : false; } void transQueueClear(STransQueue* q) { - while (!QUEUE_IS_EMPTY(q->node)) { + while (!QUEUE_IS_EMPTY(&q->node)) { queue* h = QUEUE_HEAD(&q->node); QUEUE_REMOVE(h); if (q->freeFunc != NULL) (q->freeFunc)(h); From fadfbf28242620e230587c084bcfd8a020c0b237 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 11 Sep 2024 22:21:56 +0800 Subject: [PATCH 065/240] opt parameter --- source/libs/transport/inc/transComm.h | 4 ---- source/libs/transport/src/transCli.c | 26 +++++++++++++------------- source/libs/transport/src/transComm.c | 6 +++--- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index dabed050ec..d47ad214e8 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -94,10 +94,6 @@ typedef void* queue[2]; /* Return the structure holding the given element. */ #define QUEUE_DATA(e, type, field) ((type*)((void*)((char*)(e)-offsetof(type, field)))) -typedef struct { - queue q; -} queueWrapper; - // #define TRANS_RETRY_COUNT_LIMIT 100 // retry count limit // #define TRANS_RETRY_INTERVAL 15 // retry interval (ms) #define TRANS_CONN_TIMEOUT 3000 // connect timeout (ms) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d5ec6e7e33..72f271a1f4 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -403,16 +403,16 @@ bool filteBySeq(void* key, void* arg) { } } int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { - int32_t code = 0; - queueWrapper set; - QUEUE_INIT(&set.q) + int32_t code = 0; + queue set; + QUEUE_INIT(&set) transQueueRemoveByFilter(&conn->reqsSentOut, filteBySeq, &seq, &set, 1); - if (QUEUE_IS_EMPTY(&set.q)) { + if (QUEUE_IS_EMPTY(&set)) { return TSDB_CODE_OUT_OF_RANGE; } - queue* e = QUEUE_HEAD(&set.q); + queue* e = QUEUE_HEAD(&set); SCliReq* p = QUEUE_DATA(e, SCliReq, q); *pReq = p; @@ -481,13 +481,13 @@ int32_t cliConnMayHandleState_releaseReq(SCliConn* conn, STransMsgHead* pHead) { tDebug("%s %p reqToSend:%d, sentOut:%d", CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqsToSend), transQueueSize(&conn->reqsSentOut)); - queueWrapper set; - QUEUE_INIT(&set.q); + queue set; + QUEUE_INIT(&set); transQueueRemoveByFilter(&conn->reqsSentOut, filterByQid, &qId, &set, -1); transQueueRemoveByFilter(&conn->reqsToSend, filterByQid, &qId, &set, -1); - while (!QUEUE_IS_EMPTY(&set.q)) { - queue* el = QUEUE_HEAD(&set.q); + while (!QUEUE_IS_EMPTY(&set)) { + queue* el = QUEUE_HEAD(&set); SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); QUEUE_REMOVE(el); if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { @@ -1317,12 +1317,12 @@ bool fileToRmReq(void* h, void* arg) { return false; } static void cliConnRmReqs(SCliConn* conn) { - queueWrapper set; - QUEUE_INIT(&set.q); + queue set; + QUEUE_INIT(&set); transQueueRemoveByFilter(&conn->reqsSentOut, fileToRmReq, NULL, &set, -1); - while (!QUEUE_IS_EMPTY(&set.q)) { - queue* el = QUEUE_HEAD(&set.q); + while (!QUEUE_IS_EMPTY(&set)) { + queue* el = QUEUE_HEAD(&set); QUEUE_REMOVE(el); SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); destroyReq(pReq); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index e85ce2091a..951b651ee1 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -471,14 +471,14 @@ void* transQueueGet(STransQueue* q, int idx) { } void transQueueRemoveByFilter(STransQueue* q, bool (*filter)(void* e, void* arg), void* arg, void* dst, int32_t size) { - queueWrapper* d = dst; - queue* node = QUEUE_NEXT(&q->node); + queue* d = dst; + queue* node = QUEUE_NEXT(&q->node); while (node != &q->node) { queue* next = QUEUE_NEXT(node); if (filter(node, arg)) { QUEUE_REMOVE(node); q->size--; - QUEUE_PUSH(&d->q, node); + QUEUE_PUSH(d, node); if (--size == 0) { break; } From 001834f41990920c29c85f923556d018207af62b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 12 Sep 2024 09:36:18 +0800 Subject: [PATCH 066/240] opt parameter --- source/libs/transport/inc/transComm.h | 3 +-- source/libs/transport/src/transCli.c | 32 +++++++++++++++++++++++---- source/libs/transport/src/transSvr.c | 8 +++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index d47ad214e8..6719e5788b 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -172,8 +172,7 @@ 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 toInit : 2; // 0: sent user info or not char secured : 2; char spi : 2; char hasEpSet : 2; // contain epset or not, 0(default): no epset, 1: contain epset diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 72f271a1f4..2bc2ceabf3 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -100,6 +100,8 @@ typedef struct SCliConn { int8_t registered; int8_t connnected; SHashObj* pQTable; + int8_t inited; + void* initPacket; } SCliConn; // #define TRANS_CONN_REF_INC(tconn) \ @@ -1350,6 +1352,26 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { cliSendBatch_shareConn(conn); } } +bool cliConnMayBuildInitPacket(SCliConn* pConn, STransMsgHead** pHead, int32_t msgLen) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + if (pConn->inited == 1) { + return false; + } + STransMsgHead* tHead = taosMemoryCalloc(1, msgLen + strlen(pInst->user)); + memcpy(tHead, pHead, TRANS_MSG_OVERHEAD); + memcpy(tHead + TRANS_MSG_OVERHEAD, pInst->user, strlen(pInst->user)); + + memcpy(tHead + TRANS_MSG_OVERHEAD + strlen(pInst->user), (char*)pHead + TRANS_MSG_OVERHEAD, + msgLen - TRANS_MSG_OVERHEAD); + + tHead->toInit = 1; + *pHead = tHead; + + pConn->initPacket = tHead; + pConn->inited = 1; + return true; +} void cliSendBatch_shareConn(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; @@ -1379,14 +1401,16 @@ void cliSendBatch_shareConn(SCliConn* pConn) { STransMsgHead* pHead = transHeadFromCont(pReq->pCont); + if (cliConnMayBuildInitPacket(pConn, &pHead, msgLen)) { + } else { + pHead->toInit = 0; + } + if (pHead->comp == 0) { - // pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; - pHead->persist = REQUEST_PERSIS_HANDLE(pReq) ? 1 : 0; pHead->msgType = pReq->msgType; pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; - memcpy(pHead->user, pInst->user, strlen(pInst->user)); + // memcpy(pHead->user, pInst->user, strlen(pInst->user)); pHead->traceId = pReq->info.traceId; pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->version = TRANS_VER; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index fcaf82a824..35f81377a5 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -462,6 +462,11 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { } return 0; } + +bool uvExtractFisrtInitPacket() { + + return true; +} static bool uvHandleReq(SSvrConn* pConn) { STrans* pInst = pConn->pInst; SWorkThrd* pThrd = pConn->hostThrd; @@ -685,7 +690,6 @@ static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { pMsg->contLen = 0; } STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); - // pHead->ahandle = (uint64_t)pMsg->info.ahandle; pHead->traceId = pMsg->info.traceId; pHead->hasEpSet = pMsg->info.hasEpSet; pHead->magicNum = htonl(TRANS_MAGIC_NUM); @@ -704,7 +708,7 @@ static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); // pHead->msgType = pMsg->msgType; - pHead->release = smsg->type == Release ? 1 : 0; + // pHead->release = smsg->type == Release ? 1 : 0; pHead->code = htonl(pMsg->code); pHead->msgLen = htonl(pMsg->contLen + sizeof(STransMsgHead)); From 8823358ca7c9f8f713306ecf7ded80c1c317cc92 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 12 Sep 2024 14:38:21 +0800 Subject: [PATCH 067/240] opt parameter --- source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 6 +- source/dnode/mnode/impl/src/mndMain.c | 3 +- source/libs/transport/inc/transComm.h | 9 ++- source/libs/transport/src/transCli.c | 68 ++++++++++++--------- source/libs/transport/src/transSvr.c | 36 +++++++++-- 5 files changed, 78 insertions(+), 44 deletions(-) diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 70f258a362..b695457801 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -64,7 +64,7 @@ static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) { SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_RETRIEVE_IP_WHITE, - .info.ahandle = (void *)0x9527, + .info.ahandle = 0, .info.refId = 0, .info.noResp = 0, .info.handle = 0}; @@ -180,7 +180,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, - .info.ahandle = (void *)0x9527, + .info.ahandle = 0, .info.refId = 0, .info.noResp = 0, .info.handle = 0}; @@ -229,7 +229,7 @@ void dmSendNotifyReq(SDnodeMgmt *pMgmt, SNotifyReq *pReq) { SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_NOTIFY, - .info.ahandle = (void *)0x9527, + .info.ahandle = 0, .info.refId = 0, .info.noResp = 1, .info.handle = 0}; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 25872801e4..37e54d58ae 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -210,8 +210,7 @@ static void mndPullupGrant(SMnode *pMnode) { int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { - SRpcMsg rpcMsg = { - .msgType = TDMT_MND_GRANT_HB_TIMER, .pCont = pReq, .contLen = contLen, .info.ahandle = (void *)0x9527}; + SRpcMsg rpcMsg = {.msgType = TDMT_MND_GRANT_HB_TIMER, .pCont = pReq, .contLen = contLen, .info.ahandle = 0}; // TODO check return value (void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 6719e5788b..d54db8ab5c 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -169,16 +169,15 @@ typedef struct { #define TRANS_VER 2 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 toInit : 2; // 0: sent user info or not + 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 withUserInfo : 2; // 0: sent user info or not 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]; int32_t compatibilityVer; uint32_t magicNum; STraceId traceId; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 2bc2ceabf3..3718331358 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -100,8 +100,8 @@ typedef struct SCliConn { int8_t registered; int8_t connnected; SHashObj* pQTable; - int8_t inited; - void* initPacket; + int8_t userInited; + void* pInitUserReq; } SCliConn; // #define TRANS_CONN_REF_INC(tconn) \ @@ -523,6 +523,10 @@ void cliHandleResp2(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; + if (conn->pInitUserReq) { + taosMemoryFree(conn->pInitUserReq); + conn->pInitUserReq = NULL; + } cliResetConnTimer(conn); SCliReq* pReq = NULL; @@ -1123,8 +1127,8 @@ _exception: void cliDestroyMsg(void* arg) { queue* e = arg; SCliReq* pReq = QUEUE_DATA(e, SCliReq, q); - if (pReq->msg.info.notFreeAhandle == 0) { - taosMemoryFree(pReq->ctx->ahandle); + if (pReq->msg.info.notFreeAhandle == 0 && pReq->ctx->ahandle != 0) { + // taosMemoryFree(pReq->ctx->ahandle); } destroyReq(pReq); } @@ -1233,7 +1237,11 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { transDQCancel(pThrd->timeoutQueue, conn->task); conn->task = NULL; } - // cliResetTimer(pThrd, conn); + + if (conn->pInitUserReq) { + taosMemoryFree(conn->pInitUserReq); + conn->pInitUserReq = NULL; + } if (clear) { if (!uv_is_closing((uv_handle_t*)conn->stream)) { @@ -1270,6 +1278,10 @@ static void cliDestroy(uv_handle_t* handle) { cliDestroyConnMsgs(conn, true); destroyCliConnQTable(conn); + if (conn->pInitUserReq) { + taosMemoryFree(conn->pInitUserReq); + conn->pInitUserReq = NULL; + } tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); transReqQueueClear(&conn->wreqQueue); (void)transDestroyBuffer(&conn->readBuf); @@ -1352,24 +1364,26 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { cliSendBatch_shareConn(conn); } } -bool cliConnMayBuildInitPacket(SCliConn* pConn, STransMsgHead** pHead, int32_t msgLen) { +bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msgLen) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - if (pConn->inited == 1) { + if (pConn->userInited == 1) { return false; } - STransMsgHead* tHead = taosMemoryCalloc(1, msgLen + strlen(pInst->user)); - memcpy(tHead, pHead, TRANS_MSG_OVERHEAD); - memcpy(tHead + TRANS_MSG_OVERHEAD, pInst->user, strlen(pInst->user)); + STransMsgHead* pHead = *ppHead; + STransMsgHead* tHead = taosMemoryCalloc(1, *msgLen + sizeof(pInst->user)); + memcpy((char*)tHead, (char*)pHead, TRANS_MSG_OVERHEAD); + memcpy((char*)tHead + TRANS_MSG_OVERHEAD, pInst->user, sizeof(pInst->user)); - memcpy(tHead + TRANS_MSG_OVERHEAD + strlen(pInst->user), (char*)pHead + TRANS_MSG_OVERHEAD, - msgLen - TRANS_MSG_OVERHEAD); + memcpy((char*)tHead + TRANS_MSG_OVERHEAD + sizeof(pInst->user), (char*)pHead + TRANS_MSG_OVERHEAD, + *msgLen - TRANS_MSG_OVERHEAD); - tHead->toInit = 1; - *pHead = tHead; + tHead->withUserInfo = 1; + *ppHead = tHead; + *msgLen += sizeof(pInst->user); - pConn->initPacket = tHead; - pConn->inited = 1; + pConn->pInitUserReq = tHead; + pConn->userInited = 1; return true; } void cliSendBatch_shareConn(SCliConn* pConn) { @@ -1397,20 +1411,20 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pReq->contLen = 0; } - int msgLen = transMsgLenFromCont(pReq->contLen); + int32_t msgLen = transMsgLenFromCont(pReq->contLen); STransMsgHead* pHead = transHeadFromCont(pReq->pCont); - if (cliConnMayBuildInitPacket(pConn, &pHead, msgLen)) { - } else { - pHead->toInit = 0; + char* content = pReq->pCont; + int32_t contLen = pReq->contLen; + if (cliConnMayAddUserInfo(pConn, &pHead, &msgLen)) { + content = transContFromHead(pHead); + contLen = transContLenFromMsg(msgLen); } - if (pHead->comp == 0) { pHead->noResp = REQUEST_NO_RESP(pReq) ? 1 : 0; pHead->msgType = pReq->msgType; pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); - // memcpy(pHead->user, pInst->user, strlen(pInst->user)); pHead->traceId = pReq->info.traceId; pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->version = TRANS_VER; @@ -1421,8 +1435,8 @@ void cliSendBatch_shareConn(SCliConn* pConn) { pHead->qid = taosHton64(pReq->info.qId); if (pHead->comp == 0) { - if (pInst->compressSize != -1 && pInst->compressSize < pReq->contLen) { - msgLen = transCompressMsg(pReq->pCont, pReq->contLen) + sizeof(STransMsgHead); + if (pInst->compressSize != -1 && pInst->compressSize < contLen) { + msgLen = transCompressMsg(content, contLen) + sizeof(STransMsgHead); pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); } } else { @@ -2984,10 +2998,8 @@ int32_t transReleaseCliHandle(void* handle) { return TSDB_CODE_RPC_BROKEN_LINK; } - STransMsg tmsg = {.msgType = TDMT_SCH_TASK_RELEASE, - .info.handle = handle, - .info.ahandle = (void*)0x9527, - .info.qId = (int64_t)handle}; + STransMsg tmsg = { + .msgType = TDMT_SCH_TASK_RELEASE, .info.handle = handle, .info.ahandle = (void*)0, .info.qId = (int64_t)handle}; TRACE_SET_MSGID(&tmsg.info.traceId, tGenIdPI64()); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 35f81377a5..96e369af9a 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -54,6 +54,7 @@ typedef struct SSvrConn { int spi; char info[64]; char user[TSDB_UNI_LEN]; // user ID for the link + int8_t userInited; char secret[TSDB_PASSWORD_LEN]; char ckey[TSDB_PASSWORD_LEN]; // ciphering key @@ -463,10 +464,31 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { return 0; } -bool uvExtractFisrtInitPacket() { - - return true; -} +bool uvConnMayGetUserInfo(SSvrConn* pConn, STransMsgHead** ppHead, int32_t* msgLen) { + if (pConn->userInited) { + return false; + } + + STrans* pInst = pConn->pInst; + STransMsgHead* pHead = *ppHead; + int32_t len = *msgLen; + if (pHead->withUserInfo) { + STransMsgHead* tHead = taosMemoryCalloc(1, len - sizeof(pInst->user)); + memcpy((char*)tHead, (char*)pHead, TRANS_MSG_OVERHEAD); + memcpy((char*)tHead + TRANS_MSG_OVERHEAD, (char*)pHead + TRANS_MSG_OVERHEAD + sizeof(pInst->user), + len - sizeof(STransMsgHead) - sizeof(pInst->user)); + tHead->msgLen = htonl(htonl(pHead->msgLen) - sizeof(pInst->user)); + + memcpy(pConn->user, (char*)pHead + TRANS_MSG_OVERHEAD, sizeof(pConn->user)); + pConn->userInited = 1; + + taosMemoryFree(pHead); + *ppHead = tHead; + *msgLen = len - sizeof(pInst->user); + return true; + } + return false; +} static bool uvHandleReq(SSvrConn* pConn) { STrans* pInst = pConn->pInst; SWorkThrd* pThrd = pConn->hostThrd; @@ -479,6 +501,9 @@ static bool uvHandleReq(SSvrConn* pConn) { tError("%s conn %p read invalid packet", transLabel(pInst), pConn); return false; } + if (uvConnMayGetUserInfo(pConn, &pHead, &msgLen) == true) { + } + if (resetBuf == 0) { tTrace("%s conn %p not reset read buf", transLabel(pInst), pConn); } @@ -487,12 +512,10 @@ static bool uvHandleReq(SSvrConn* pConn) { tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); return false; } - // pHead->ahandle = htole64(pHead->ahandle); pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); pConn->inType = pHead->msgType; - memcpy(pConn->user, pHead->user, strlen(pHead->user)); int8_t forbiddenIp = 0; if (pThrd->enableIpWhiteList && tsEnableWhiteList) { @@ -697,6 +720,7 @@ static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { pHead->version = TRANS_VER; pHead->seqNum = htonl(pMsg->info.seqNum); pHead->qid = taosHton64(pMsg->info.qId); + pHead->withUserInfo = pConn->userInited == 0 ? 1 : 0; // handle invalid drop_task resp, TD-20098 if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { From 2f487130ce3b8b53b189a21db217eb5d08eb9d74 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 12 Sep 2024 17:39:39 +0800 Subject: [PATCH 068/240] opt parameter --- source/libs/transport/src/transCli.c | 20 ++++----- source/libs/transport/src/transSvr.c | 63 +++++++++------------------- 2 files changed, 27 insertions(+), 56 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3718331358..4e7515b12c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -465,7 +465,9 @@ int32_t cliConnMayHandleState_releaseReq(SCliConn* conn, STransMsgHead* pHead) { if (pHead->msgType == TDMT_SCH_TASK_RELEASE || pHead->msgType == TDMT_SCH_TASK_RELEASE + 1) { int64_t qId = taosHton64(pHead->qid); STraceId* trace = &pHead->traceId; - tGDebug("%s conn %p receive release req, qid:%ld", CONN_GET_INST_LABEL(conn), conn, qId); + int32_t seqNum = htonl(pHead->seqNum); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seqNum:%d, qid:%ld", CONN_GET_INST_LABEL(conn), + conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, seqNum, qId); STransCtx* p = taosHashGet(conn->pQTable, &qId, sizeof(qId)); transCtxCleanup(p); @@ -569,8 +571,8 @@ void cliHandleResp2(SCliConn* conn) { qId, tstrerror(code)); } if (code != 0) { - tDebug("%s conn %p recv unexpected packet, seqNum:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, - tstrerror(code)); + tDebug("%s conn %p recv unexpected packet, seqNum:%d, qId:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, + qId, tstrerror(code)); // TODO: notify cb if (cliMayRecycleConn(conn)) { return; @@ -3433,7 +3435,7 @@ int32_t transAllocHandle(int64_t* refId) { QUEUE_INIT(&exh->q); taosInitRWLatch(&exh->latch); - tDebug("alloc qid:%ld", exh->refId); + tDebug("trans alloc qid:%ld", exh->refId); *refId = exh->refId; return 0; } @@ -3459,7 +3461,7 @@ int32_t transFreeConnById(void* pInstRef, int64_t transpointId) { } pCli->type = Normal; - tDebug("release conn id %" PRId64 "", transpointId); + tDebug("%s release conn id %" PRId64 "", pInst->label, transpointId); STransMsg msg = {.msgType = TDMT_SCH_TASK_RELEASE, .info.handle = (void*)transpointId}; msg.info.qId = transpointId; @@ -3513,14 +3515,6 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } code = transHeapGet(pHeap, &pConn); - // if (pConn && taosHashGetSifze(pConn->pQTable) > 0) { - // tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, - // pConn->reqRefCnt); return NULL; - // } /*else { - // // tDebug("failed to get conn from heap cache for key:%s", key); - // // return NULL; - // }*/ - if (code != 0) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 96e369af9a..30b9053979 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -167,9 +167,6 @@ static void uvNotifyLinkBrokenToApp(SSvrConn* conn); static FORCE_INLINE void destroySmsg(SSvrRespMsg* smsg); 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 int32_t reallocConnRef(SSvrConn* conn); int32_t uvGetConnRefOfThrd(SWorkThrd* thrd) { return thrd ? thrd->connRefMgt : -1; } @@ -1309,43 +1306,26 @@ static FORCE_INLINE void destroyConn(SSvrConn* conn, bool clear) { } } } -// static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn) { -// if (conn->regArg.init == 1) { -// transFreeMsg(conn->regArg.msg.pCont); -// conn->regArg.init = 0; -// } -// } -static int32_t reallocConnRef(SSvrConn* conn) { - if (conn->refId > 0) { - (void)transReleaseExHandle(uvGetConnRefOfThrd(conn->hostThrd), conn->refId); - (void)transRemoveExHandle(uvGetConnRefOfThrd(conn->hostThrd), 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; + +void uvConnDestroyAllState(SSvrConn* p) { + STrans* pInst = p->pInst; + SHashObj* pQTable = p->pQTable; + if (pQTable == NULL) return; + + void* pIter = taosHashIterate(pQTable, NULL); + while (pIter) { + SSvrRegArg* arg = pIter; + int64_t* qid = taosHashGetKey(pIter, NULL); + (pInst->cfp)(pInst->parent, &(arg->msg), NULL); + tTrace("conn %p broken, notify server app, qid%ld", p, *qid); + pIter = taosHashIterate(pQTable, pIter); } - exh->handle = conn; - exh->pThrd = conn->hostThrd; - exh->refId = transAddExHandle(uvGetConnRefOfThrd(conn->hostThrd), exh); - if (exh->refId < 0) { - taosMemoryFree(exh); - return TSDB_CODE_REF_INVALID_ID; - } - - QUEUE_INIT(&exh->q); - SExHandle* pSelf = transAcquireExHandle(uvGetConnRefOfThrd(conn->hostThrd), 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; + taosHashCleanup(pQTable); + pQTable = NULL; + return; } + static void uvDestroyConn(uv_handle_t* handle) { SSvrConn* conn = handle->data; @@ -1360,18 +1340,15 @@ static void uvDestroyConn(uv_handle_t* handle) { STrans* pInst = thrd->pInst; tDebug("%s conn %p destroy", transLabel(pInst), conn); - // for (int i = 0; i < transQueueSize(&conn->resps); i++) { - // SSvrRespMsg* msg = transQueueGet(&conn->resps, i); - // destroySmsg(msg); - // } transQueueDestroy(&conn->resps); transReqQueueClear(&conn->wreqQueue); QUEUE_REMOVE(&conn->queue); - taosHashCleanup(conn->pQTable); taosMemoryFree(conn->pTcp); - // destroyConnRegArg(conn); + + uvConnDestroyAllState(conn); + (void)transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); From 1bac4a8cf0a94c225596da344b79b5ce76a64a19 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 12 Sep 2024 19:37:44 +0800 Subject: [PATCH 069/240] opt parameter --- include/util/taoserror.h | 7 +- source/libs/transport/src/transCli.c | 142 +++++++++++++-------------- source/util/src/terror.c | 1 + 3 files changed, 68 insertions(+), 82 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 534f7d0505..5b42716c03 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -94,12 +94,7 @@ int32_t taosGetErrSize(); #define TSDB_CODE_RPC_ASYNC_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0027) #define TSDB_CODE_RPC_ASYNC_IN_PROCESS TAOS_DEF_ERROR_CODE(0, 0x0028) #define TSDB_CODE_RPC_NO_STATE TAOS_DEF_ERROR_CODE(0, 0x0029) - - - - - - +#define TSDB_CODE_RPC_STATE_DROPED TAOS_DEF_ERROR_CODE(0, 0x002A) //common & util #define TSDB_CODE_OPS_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x0100) // diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4e7515b12c..04a90d7765 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -212,7 +212,7 @@ static FORCE_INLINE void cliAllocRecvBufferCb(uv_handle_t* handle, size_t sugges // callback after recv nbytes from socket static void cliRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf); // callback after send data to socket -static void cliSendCb(uv_write_t* req, int status); +// static void cliSendCb(uv_write_t* req, int status); // callback after conn to server static void cliConnCb(uv_connect_t* req, int status); static void cliAsyncCb(uv_async_t* handle); @@ -620,16 +620,16 @@ void cliConnTimeout(uv_timer_t* handle) { tTrace("%s conn %p conn timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, TRANS_CONN_REF_GET(conn)); cliResetConnTimer(conn); - cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - cliHandleFastFail(conn, UV_ECANCELED); -} -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, TRANS_CONN_REF_GET(conn)); - (void)uv_read_stop(conn->stream); - cliHandleExceptImpl(conn, TSDB_CODE_RPC_TIMEOUT); + // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); + // cliHandleFastFail(conn, UV_ECANCELED); } +// 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, TRANS_CONN_REF_GET(conn)); +// (void)uv_read_stop(conn->stream); +// cliHandleExceptImpl(conn, TSDB_CODE_RPC_TIMEOUT); +// } void* createConnPool(int size) { // thread local, no lock @@ -1070,45 +1070,6 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { } } -// static int32_t cliAddReqToConn(SCliConn* conn, SCliReq* pReq) { -// if (transQueuePush(&conn->reqsToSend, pReq) != 0) { -// return TSDB_CODE_OUT_OF_MEMORY; -// } -// return 0; -// } - -// static int32_t cliRmReqFromConn(SCliConn* conn, SCliReq** pReq) { -// // do nothing -// SCliReq* pTail = transQueuePop(&conn->reqsToSend); -// if (pTail == NULL) { -// return TSDB_CODE_INVALID_PARA; -// } -// if (pReq != NULL) { -// *pReq = pTail; -// } -// return 0; -// } -// static int32_t cliPutQReqToTable(SCliConn* pConn, SCliReq* pReq) { -// int32_t code = 0; -// if (pReq->msg.info.handle == 0) { -// return 0; -// } - -// queue q; -// QUEUE_INIT(&q); - -// queue* p = taosHashGet(pConn->pQueryTable, (void*)pReq->msg.info.handle, sizeof(int64_t)); -// if (p == NULL) { -// QUEUE_PUSH(&q, &pReq->qlist); -// code = taosHashPut(pConn->pQueryTable, (void*)pReq->msg.info.handle, sizeof(int64_t), &q, sizeof(queue)); -// if (code != 0) { -// return code; -// } -// } else { -// QUEUE_PUSH(p, &pReq->qlist); -// } -// return 0; -// } static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) { int32_t code = 0; SCliConn* pConn = NULL; @@ -1291,37 +1252,44 @@ static void cliDestroy(uv_handle_t* handle) { taosMemoryFree(conn); } +bool filterAllReq(void* e, void* arg) { return 1; } + static void cliHandleBatch_shareConnExcept(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - while (!transQueueEmpty(&conn->reqsToSend)) { - queue* el = transQueuePop(&conn->reqsToSend); + + queue set; + transQueueRemoveByFilter(&conn->reqsSentOut, filterAllReq, NULL, &set, -1); + transQueueRemoveByFilter(&conn->reqsToSend, filterAllReq, NULL, &set, -1); + + while (!QUEUE_IS_EMPTY(&set)) { + queue* el = QUEUE_HEAD(&set); + QUEUE_REMOVE(el); + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); - // ASSERT(pReq->type != Release); - // ASSERT(REQUEST_NO_RESP(&pReq->msg) == 0); - - SReqCtx* pCtx = pReq ? pReq->ctx : NULL; + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; STransMsg resp = {0}; - resp.code = code == -1 ? (conn->broken ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL) : code; + resp.code = (conn->connnected ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL); resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; - resp.info.ahandle = NULL; resp.info.cliVer = pInst->compatibilityVer; - resp.info.ahandle = pCtx->ahandle; + resp.info.ahandle = pCtx ? pCtx->ahandle : 0; + // not + if (pCtx == NULL) { + destroyReq(pReq); + continue; + } pReq->seq = 0; code = cliNotifyCb(conn, pReq, &resp); - if (code != 0) { + if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { continue; } else { // already notify user destroyReq(pReq); } } - - if (TRANS_CONN_REF_GET(conn) > 1) transUnrefCliHandle(conn); - transUnrefCliHandle(conn); } bool fileToRmReq(void* h, void* arg) { @@ -1611,6 +1579,23 @@ int32_t cliConnSetSockInfo(SCliConn* pConn) { return 0; }; + +static int32_t cliBuildExeceptMsg(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + memset(pResp, 0, sizeof(STransMsg)); + STransMsg resp = {0}; + resp.contLen = 0; + resp.pCont = NULL; + resp.msgType = pReq->msg.msgType + 1; + resp.info.ahandle = pReq->ctx->ahandle; + resp.info.traceId = pReq->msg.info.traceId; + resp.info.hasEpSet = false; + resp.info.cliVer = pInst->compatibilityVer; + return 0; +} + +bool filteGetAll(void* q, void* arg) { return true; } void cliConnCb(uv_connect_t* req, int status) { SCliConn* pConn = req->data; SCliThrd* pThrd = pConn->hostThrd; @@ -1627,16 +1612,16 @@ void cliConnCb(uv_connect_t* req, int status) { if (status != 0) { tDebug("%s conn %p failed to connect to %s, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, uv_strerror(status)); - // handle err - // 1. update statis - // 2. notifyCb or retry - // 3. clear conn and - // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, pConn->dstAddr); - // if (timeout == false) { - // cliHandleFastFail(pConn, status); - // } else if (timeout == true) { - // // already deal by timeout + // queue set; + // transQueueRemoveByFilter(&pConn->reqsToSend, filteGetAll, NULL, &set, -1); + // transQueueRemoveByFilter(&pConn->reqsSentOut, filteGetAll, NULL, &set, -1); + // while (!QUEUE_IS_EMPTY(&set)) { + // queue* el = QUEUE_HEAD(&set); + // SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + // cliBuildExeceptMsg(pConn, pReq, &pReq->msg); + // destroyReq(pReq); // } + cliHandleExcept(pConn, status); return; } pConn->connnected = 1; @@ -1894,9 +1879,12 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { } SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); + if (pState == NULL) { + if (pReq->ctx == NULL || pReq->ctx->ahandle == 0) { + return TSDB_CODE_RPC_STATE_DROPED; + } tDebug("failed to get statue, qid:%ld", qid); - // ASSERT(0); return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { *pConn = pState->conn; @@ -1939,6 +1927,11 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { code = cliMayGetStateByQid(pThrd, pReq, &pConn); if (code == 0) { (void)clConnMayUpdateReqCtx(pConn, pReq); + } else if (code == TSDB_CODE_RPC_STATE_DROPED) { + STraceId* trace = &pReq->msg.info.traceId; + tWarn("%s failed to get statue, qid:%ld", pInst->label, pReq->msg.info.qId); + destroyReq(pReq); + return; } if (code == TSDB_CODE_RPC_NO_STATE || code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { @@ -2217,6 +2210,7 @@ static FORCE_INLINE void destroyReq(void* arg) { if (pReq == NULL) { return; } + tDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); if (pReq->ctx) destroyReqCtx(pReq->ctx); @@ -2802,7 +2796,6 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); noDelay = cliResetEpset(pCtx, pResp, false); transFreeMsg(pResp->pCont); - // transUnrefCliHandle(pConn); } else if (code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_INTERNAL_ERROR || code == TSDB_CODE_SYN_PROPOSE_NOT_READY || code == TSDB_CODE_VND_STOPPED || code == TSDB_CODE_MNODE_NOT_FOUND || code == TSDB_CODE_APP_IS_STARTING || @@ -2810,16 +2803,13 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { tTrace("code str %s, contlen:%d 1", tstrerror(code), pResp->contLen); noDelay = cliResetEpset(pCtx, pResp, true); transFreeMsg(pResp->pCont); - // addConnToPool(pThrd->pool, pConn); } else if (code == TSDB_CODE_SYN_RESTORING) { tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); noDelay = cliResetEpset(pCtx, pResp, true); - // addConnToPool(pThrd->pool, pConn); transFreeMsg(pResp->pCont); } else { tTrace("code str %s, contlen:%d 0", tstrerror(code), pResp->contLen); noDelay = cliResetEpset(pCtx, pResp, false); - // addConnToPool(pThrd->pool, pConn); transFreeMsg(pResp->pCont); } if (code != TSDB_CODE_RPC_BROKEN_LINK && code != TSDB_CODE_RPC_NETWORK_UNAVAIL && code != TSDB_CODE_SUCCESS) { diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 8cec54ee68..78cee5bb77 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -61,6 +61,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MODULE_QUIT, "rpc module already qu TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_MODULE_QUIT, "rpc async module already quit") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_IN_PROCESS, "rpc async in process") TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NO_STATE, "rpc no state") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_STATE_DROPED, "rpc state already dropped") //common & util TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized") From 24a2da04c1f1c495438e4fbd9ddaa9f477e5a936 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 08:21:00 +0800 Subject: [PATCH 070/240] opt parameter --- source/libs/transport/src/transCli.c | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 04a90d7765..f1d1cd6284 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -238,6 +238,7 @@ void destroyCliConnQTable(SCliConn* conn) { // static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); +static void cliHandleBatch_shareConnExcept(SCliConn* conn); static int32_t allocConnRef(SCliConn* conn, bool update); static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); @@ -921,7 +922,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { if (TRANS_CONN_REF_GET(conn) > 1) { transUnrefCliHandle(conn); } - cliDestroyConnMsgs(conn, false); + // cliDestroyConnMsgs(conn, false); if (conn->list == NULL && conn->dstAddr != NULL) { conn->list = taosHashGet((SHashObj*)pool, conn->dstAddr, strlen(conn->dstAddr)); @@ -1046,7 +1047,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { while (transReadComplete(pBuf)) { tTrace("%s conn %p read complete", CONN_GET_INST_LABEL(conn), conn); if (pBuf->invalid) { - cliHandleExcept(conn, -1); + return cliHandleBatch_shareConnExcept(conn); break; } else { cliHandleResp2(conn); @@ -1238,7 +1239,7 @@ static void cliDestroy(uv_handle_t* handle) { tDebug("%s conn %p destroy state %ld", CONN_GET_INST_LABEL(conn), conn, *qid); } - cliDestroyConnMsgs(conn, true); + // cliDestroyConnMsgs(conn, true); destroyCliConnQTable(conn); if (conn->pInitUserReq) { @@ -1260,6 +1261,10 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { STrans* pInst = pThrd->pInst; queue set; + QUEUE_INIT(&set); + // TODO + // 1. from qId from thread table + // 2. not itera to all reqs transQueueRemoveByFilter(&conn->reqsSentOut, filterAllReq, NULL, &set, -1); transQueueRemoveByFilter(&conn->reqsToSend, filterAllReq, NULL, &set, -1); @@ -1275,8 +1280,13 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; resp.info.cliVer = pInst->compatibilityVer; resp.info.ahandle = pCtx ? pCtx->ahandle : 0; - // not - if (pCtx == NULL) { + if (pReq) { + resp.info.traceId = pReq->msg.info.traceId; + } + // resp.info.traceId = pReq ? pReq->msg.info.traceId : {0, 0}; + + // handle noresp and inter manage msg + if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { destroyReq(pReq); continue; } @@ -1290,6 +1300,9 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { destroyReq(pReq); } } + if (!uv_is_closing((uv_handle_t*)conn->stream)) { + uv_close((uv_handle_t*)conn->stream, cliDestroy); + } } bool fileToRmReq(void* h, void* arg) { @@ -1612,16 +1625,7 @@ void cliConnCb(uv_connect_t* req, int status) { if (status != 0) { tDebug("%s conn %p failed to connect to %s, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, uv_strerror(status)); - // queue set; - // transQueueRemoveByFilter(&pConn->reqsToSend, filteGetAll, NULL, &set, -1); - // transQueueRemoveByFilter(&pConn->reqsSentOut, filteGetAll, NULL, &set, -1); - // while (!QUEUE_IS_EMPTY(&set)) { - // queue* el = QUEUE_HEAD(&set); - // SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); - // cliBuildExeceptMsg(pConn, pReq, &pReq->msg); - // destroyReq(pReq); - // } - cliHandleExcept(pConn, status); + cliHandleBatch_shareConnExcept(pConn); return; } pConn->connnected = 1; @@ -1881,7 +1885,7 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); if (pState == NULL) { - if (pReq->ctx == NULL || pReq->ctx->ahandle == 0) { + if (pReq->ctx == NULL) { return TSDB_CODE_RPC_STATE_DROPED; } tDebug("failed to get statue, qid:%ld", qid); From d3634f89996e6dc7c30e9faa51ac9f63dc786b68 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 13:32:08 +0800 Subject: [PATCH 071/240] opt parameter --- source/client/src/clientHb.c | 42 +- source/libs/transport/inc/transComm.h | 5 +- source/libs/transport/src/trans.c | 2 +- source/libs/transport/src/transCli.c | 632 +++++--------------------- 4 files changed, 146 insertions(+), 535 deletions(-) diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 70a519d8ae..a63aedc02c 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -16,10 +16,10 @@ #include "catalog.h" #include "clientInt.h" #include "clientLog.h" -#include "scheduler.h" -#include "trpc.h" -#include "tglobal.h" #include "clientMonitor.h" +#include "scheduler.h" +#include "tglobal.h" +#include "trpc.h" typedef struct { union { @@ -245,11 +245,9 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog goto _return; } - TSC_ERR_JRET(catalogUpdateDBVgInfo(pCatalog, - (rsp->useDbRsp->db[0] == 'i') ? - TSDB_PERFORMANCE_SCHEMA_DB : - TSDB_INFORMATION_SCHEMA_DB, - rsp->useDbRsp->uid, vgInfo)); + TSC_ERR_JRET(catalogUpdateDBVgInfo( + pCatalog, (rsp->useDbRsp->db[0] == 'i') ? TSDB_PERFORMANCE_SCHEMA_DB : TSDB_INFORMATION_SCHEMA_DB, + rsp->useDbRsp->uid, vgInfo)); } } } @@ -557,7 +555,6 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { } } - taosHashRelease(pAppHbMgr->activeInfo, pReq); return TSDB_CODE_SUCCESS; @@ -610,8 +607,8 @@ static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) { } pInst->monitorParas = pRsp.monitorParas; - tscDebug("[monitor] paras from hb, clusterId:%" PRIx64 " monitorParas threshold:%d scope:%d", - pInst->clusterId, pRsp.monitorParas.tsSlowLogThreshold, pRsp.monitorParas.tsSlowLogScope); + tscDebug("[monitor] paras from hb, clusterId:%" PRIx64 " monitorParas threshold:%d scope:%d", pInst->clusterId, + pRsp.monitorParas.tsSlowLogThreshold, pRsp.monitorParas.tsSlowLogScope); if (rspNum) { tscDebug("hb got %d rsp, %d empty rsp received before", rspNum, @@ -1109,7 +1106,8 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req if (clientHbMgr.appHbHash) { code = taosHashPut(clientHbMgr.appHbHash, &hbParam->clusterId, sizeof(uint64_t), NULL, 0); if (TSDB_CODE_SUCCESS != code) { - tscWarn("hbQueryHbReqHandle put clusterId failed, clusterId:%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code)); + tscWarn("hbQueryHbReqHandle put clusterId failed, clusterId:%" PRIx64 ", error:%s", hbParam->clusterId, + tstrerror(code)); return code; } } @@ -1262,7 +1260,7 @@ int32_t hbGatherAppInfo(void) { SAppHbMgr *pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, i); if (pAppHbMgr == NULL) continue; - int64_t clusterId = pAppHbMgr->pAppInstInfo->clusterId; + int64_t clusterId = pAppHbMgr->pAppInstInfo->clusterId; SAppHbReq *pApp = taosHashGet(clientHbMgr.appSummary, &clusterId, sizeof(clusterId)); if (NULL == pApp) { (void)memcpy(&req.summary, &pAppHbMgr->pAppInstInfo->summary, sizeof(req.summary)); @@ -1304,8 +1302,7 @@ static void *hbThreadFunc(void *param) { return NULL; } if (sz > 1 && !clientHbMgr.appHbHash) { - clientHbMgr.appHbHash = - taosHashInit(0, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_NO_LOCK); + clientHbMgr.appHbHash = taosHashInit(0, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_NO_LOCK); if (NULL == clientHbMgr.appHbHash) { tscError("taosHashInit failed"); return NULL; @@ -1325,13 +1322,13 @@ static void *hbThreadFunc(void *param) { continue; } SClientHbBatchReq *pReq = NULL; - int32_t code = hbGatherAllInfo(pAppHbMgr, &pReq); + int32_t code = hbGatherAllInfo(pAppHbMgr, &pReq); if (TSDB_CODE_SUCCESS != code || taosArrayGetP(clientHbMgr.appHbMgrs, i) == NULL) { terrno = code ? code : TSDB_CODE_OUT_OF_RANGE; tFreeClientHbBatchReq(pReq); continue; } - int tlen = tSerializeSClientHbBatchReq(NULL, 0, pReq); + int tlen = tSerializeSClientHbBatchReq(NULL, 0, pReq); if (tlen == -1) { tFreeClientHbBatchReq(pReq); break; @@ -1369,9 +1366,8 @@ static void *hbThreadFunc(void *param) { pInfo->requestObjRefId = 0; SAppInstInfo *pAppInstInfo = pAppHbMgr->pAppInstInfo; - int64_t transporterId = 0; SEpSet epSet = getEpSet_s(&pAppInstInfo->mgmtEp); - if (TSDB_CODE_SUCCESS != asyncSendMsgToServer(pAppInstInfo->pTransporter, &epSet, &transporterId, pInfo)) { + if (TSDB_CODE_SUCCESS != asyncSendMsgToServer(pAppInstInfo->pTransporter, &epSet, NULL, pInfo)) { tscWarn("failed to async send msg to server"); } tFreeClientHbBatchReq(pReq); @@ -1390,7 +1386,7 @@ static void *hbThreadFunc(void *param) { } static int32_t hbCreateThread() { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; TdThreadAttr thAttr; TSC_ERR_JRET(taosThreadAttrInit(&thAttr)); TSC_ERR_JRET(taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE)); @@ -1468,9 +1464,9 @@ int32_t appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key, SAppHbMgr **pAppHbMg TSC_ERR_JRET(taosThreadMutexLock(&clientHbMgr.lock)); if (taosArrayPush(clientHbMgr.appHbMgrs, &(*pAppHbMgr)) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - (void)taosThreadMutexUnlock(&clientHbMgr.lock); - goto _return; + code = TSDB_CODE_OUT_OF_MEMORY; + (void)taosThreadMutexUnlock(&clientHbMgr.lock); + goto _return; } (*pAppHbMgr)->idx = taosArrayGetSize(clientHbMgr.appHbMgrs) - 1; TSC_ERR_JRET(taosThreadMutexUnlock(&clientHbMgr.lock)); diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index d54db8ab5c..a0695bb5d3 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -311,8 +311,9 @@ int32_t transSetConnOption(uv_tcp_t* stream, int keepalive); void transRefSrvHandle(void* handle); void transUnrefSrvHandle(void* handle); -void transRefCliHandle(void* handle); -void transUnrefCliHandle(void* handle); +void transRefCliHandle(void* handle); +int32_t transUnrefCliHandle(void* handle); +int32_t transGetRefCount(void* handle); int32_t transReleaseCliHandle(void* handle); int32_t transReleaseSrvHandle(void* handle); diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index ff53d01ca0..53df76f866 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -21,7 +21,7 @@ void* (*taosInitHandle[])(uint32_t ip, uint32_t port, char* label, int32_t numOf void (*taosCloseHandle[])(void* arg) = {transCloseServer, transCloseClient}; void (*taosRefHandle[])(void* handle) = {transRefSrvHandle, transRefCliHandle}; -void (*taosUnRefHandle[])(void* handle) = {transUnrefSrvHandle, transUnrefCliHandle}; +void (*taosUnRefHandle[])(void* handle) = {transUnrefSrvHandle, NULL}; int (*transReleaseHandle[])(void* handle) = {transReleaseSrvHandle, transReleaseCliHandle}; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f1d1cd6284..206253f9c2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -95,7 +95,6 @@ typedef struct SCliConn { int64_t refId; int32_t seq; - int32_t shareCnt; int8_t registered; int8_t connnected; @@ -104,17 +103,9 @@ typedef struct SCliConn { void* pInitUserReq; } SCliConn; -// #define TRANS_CONN_REF_INC(tconn) \ -// do { \ -// if (tcond) (tconn)->ref++; \ -// } while (0) - -// #define TRANS_CONN_REF_DEC(tcond) if (tcond) (tconn)\ -// do { \ -// if (tcond) (tconn)->ref--; \ -// } while (0) - -#define TRANS_CONN_REF_GET(tconn) ((tconn) ? (tconn)->ref : 0) +// #define TRANS_CONN_REF_INC(tconn) ((tconn) ? (tconn)->ref++ : 0) +// #define TRANS_CONN_REF_DEC(tconn) ((tconn) ? (tconn)->ref-- : 0) +// #define TRANS_CONN_REF_GET(tconn) ((tconn) ? (tconn)->ref : 0) typedef struct { SCliConn* conn; @@ -216,27 +207,11 @@ static void cliRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf); // callback after conn to server static void cliConnCb(uv_connect_t* req, int status); static void cliAsyncCb(uv_async_t* handle); -// static void cliIdleCb(uv_idle_t* handle); -// static void cliPrepareCb(uv_prepare_t* handle); - -// static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd); static void cliSendBatchCb(uv_write_t* req, int status); SCliBatch* cliGetHeadFromList(SCliBatchList* pList); -void destroyCliConnQTable(SCliConn* conn) { - void* pIter = taosHashIterate(conn->pQTable, NULL); - while (pIter != NULL) { - int64_t* qid = taosHashGetKey(pIter, NULL); - STransCtx* ctx = pIter; - transCtxCleanup(ctx); - pIter = taosHashIterate(conn->pQTable, pIter); - } - taosHashCleanup(conn->pQTable); - conn->pQTable = NULL; -} - -// static bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead); +static void destroyCliConnQTable(SCliConn* conn); static void cliHandleBatch_shareConnExcept(SCliConn* conn); static int32_t allocConnRef(SCliConn* conn, bool update); @@ -246,12 +221,10 @@ void cliResetConnTimer(SCliConn* conn); static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/); static void cliDestroy(uv_handle_t* handle); -// static int32_t 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, SCliReq** pReq); +static void doFreeTimeoutMsg(void* param); static void cliDestroyBatch(SCliBatch* pBatch); // cli util func @@ -259,7 +232,8 @@ static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx); static FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr); static FORCE_INLINE int32_t cliBuildExceptResp(SCliReq* pReq, STransMsg* resp); -static FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliReq* pReq, int32_t code); + +// static FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliReq* pReq, int32_t code); static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ipaddr); static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn); @@ -267,9 +241,6 @@ 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 // handle except about conn -static void cliHandleExcept(SCliConn* conn, int32_t code); -// static void cliReleaseUnfinishedMsg(SCliConn* conn); -static void cliHandleFastFail(SCliConn* pConn, int status); static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code); // handle req from app @@ -344,14 +315,7 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p); #define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para)) #define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pInst))->label) -// #define CONN_NO_PERSIST_BY_APP(conn) \ -// (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && TRANS_CONN_REF_GET(conn) == 1) -// #define CONN_RELEASE_BY_SERVER(conn) \ -// (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && TRANS_CONN_REF_GET(conn) == 1) - -#define REQUEST_NO_RESP(msg) ((msg)->info.noResp == 1) -#define REQUEST_PERSIS_HANDLE(msg) ((msg)->info.persistHandle == 1) -#define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release) +#define REQUEST_NO_RESP(msg) ((msg)->info.noResp == 1) #define EPSET_IS_VALID(epSet) ((epSet) != NULL && (epSet)->numOfEps >= 0 && (epSet)->inUse >= 0) #define EPSET_GET_SIZE(epSet) (epSet)->numOfEps @@ -396,6 +360,17 @@ void cliResetConnTimer(SCliConn* conn) { void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } +void destroyCliConnQTable(SCliConn* conn) { + void* pIter = taosHashIterate(conn->pQTable, NULL); + while (pIter != NULL) { + int64_t* qid = taosHashGetKey(pIter, NULL); + STransCtx* ctx = pIter; + transCtxCleanup(ctx); + pIter = taosHashIterate(conn->pQTable, pIter); + } + taosHashCleanup(conn->pQTable); + conn->pQTable = NULL; +} bool filteBySeq(void* key, void* arg) { int32_t* seq = arg; SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); @@ -492,13 +467,13 @@ int32_t cliConnMayHandleState_releaseReq(SCliConn* conn, STransMsgHead* pHead) { transQueueRemoveByFilter(&conn->reqsToSend, filterByQid, &qId, &set, -1); while (!QUEUE_IS_EMPTY(&set)) { - queue* el = QUEUE_HEAD(&set); - SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + queue* el = QUEUE_HEAD(&set); QUEUE_REMOVE(el); - if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { - pThrd->destroyAhandleFp(pReq->ctx->ahandle); - } - destroyReq(pReq); + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + + STraceId* trace = &pReq->msg.info.traceId; + tGDebug("start to free msg %p", pReq); + destroyReqWrapper(pReq, pThrd); } taosMemoryFree(pHead); return 1; @@ -521,7 +496,7 @@ int32_t cliMayHandleState(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp TMSG_INFO(pHead->msgType)); return 0; } -void cliHandleResp2(SCliConn* conn) { +void cliHandleResp(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; @@ -602,35 +577,21 @@ void cliHandleResp2(SCliConn* conn) { if (cliMayRecycleConn(conn)) { return; } + transRefCliHandle(conn); (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } -void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { return; } -void cliHandleExcept(SCliConn* conn, int32_t code) { - tTrace("%s conn %p except ref:%d", CONN_GET_INST_LABEL(conn), conn, TRANS_CONN_REF_GET(conn)); - if (code != TSDB_CODE_RPC_FQDN_ERROR) { - code = -1; - } - cliHandleExceptImpl(conn, -1); -} - void cliConnTimeout(uv_timer_t* handle) { SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; + int32_t ref = transUnrefCliHandle(conn); + if (ref <= 0) { + cliResetConnTimer(conn); + return; + } - tTrace("%s conn %p conn timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, TRANS_CONN_REF_GET(conn)); - - cliResetConnTimer(conn); - // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - // cliHandleFastFail(conn, UV_ECANCELED); + tTrace("%s conn %p conn timeout", CONN_GET_INST_LABEL(conn)); } -// 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, TRANS_CONN_REF_GET(conn)); -// (void)uv_read_stop(conn->stream); -// cliHandleExceptImpl(conn, TSDB_CODE_RPC_TIMEOUT); -// } void* createConnPool(int size) { // thread local, no lock @@ -641,25 +602,12 @@ void* destroyConnPool(SCliThrd* pThrd) { SConnList* connList = taosHashIterate((SHashObj*)pool, NULL); while (connList != NULL) { while (!QUEUE_IS_EMPTY(&connList->conns)) { - queue* h = QUEUE_HEAD(&connList->conns); + queue* h = QUEUE_HEAD(&connList->conns); + QUEUE_REMOVE(h); SCliConn* c = QUEUE_DATA(h, SCliConn, q); cliDestroyConn(c, true); } - SMsgList* msglist = connList->list; - while (!QUEUE_IS_EMPTY(&msglist->msgQ)) { - queue* h = QUEUE_HEAD(&msglist->msgQ); - QUEUE_REMOVE(h); - - SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - - transDQCancel(pThrd->waitConnQueue, pReq->ctx->task); - pReq->ctx->task = NULL; - - doNotifyCb(pReq, pThrd, TSDB_CODE_RPC_MAX_SESSIONS); - } - taosMemoryFree(msglist); - connList = taosHashIterate((SHashObj*)pool, connList); } taosHashCleanup(pool); @@ -798,117 +746,6 @@ static int32_t cliGetOrCreateConn(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pCo } return code; } -static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliReq** pReq) { - void* pool = pThrd->pool; - STrans* pInst = pThrd->pInst; - size_t klen = strlen(key); - SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); - if (plist == NULL) { - SConnList list = {0}; - (void)taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); - plist = taosHashGet(pool, key, klen); - - SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); - if (nList == NULL) { - // doNotifyApp(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - *pReq = NULL; - return NULL; - } - QUEUE_INIT(&nList->msgQ); - nList->numOfConn++; - - QUEUE_INIT(&plist->conns); - plist->list = nList; - } - - // STraceId* trace = &(*pReq)->msg.info.traceId; - // // no avaliable conn in pool - // if (QUEUE_IS_EMPTY(&plist->conns)) { - // SMsgList* list = plist->list; - // if ((list)->numOfConn >= pInst->connLimitNum) { - // STraceId* trace = &(*pReq)->msg.info.traceId; - // if (pInst->notWaitAvaliableConn || (pInst->noDelayFp != NULL && pInst->noDelayFp((*pReq)->msg.msgType))) { - // tDebug("%s msg %s not to send, reason: %s", pInst->label, TMSG_INFO((*pReq)->msg.msgType), - // tstrerror(TSDB_CODE_RPC_NETWORK_BUSY)); - // doNotifyCb(*pReq, pThrd, TSDB_CODE_RPC_NETWORK_BUSY); - // *pReq = NULL; - // return NULL; - // } - - // STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); - // if (arg == NULL) { - // doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - // *pReq = NULL; - // return NULL; - // } - // arg->param1 = *pReq; - // arg->param2 = pThrd; - - // SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); - // if (task == NULL) { - // taosMemoryFree(arg); - // doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - // *pReq = NULL; - // return NULL; - // } - // (*pReq)->ctx->task = task; - // tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); - // QUEUE_PUSH(&(list)->msgQ, &(*pReq)->q); - // *pReq = NULL; - // } else { - // // send msg in delay queue - // if (!(QUEUE_IS_EMPTY(&(list)->msgQ))) { - // STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); - // if (arg == NULL) { - // doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - // *pReq = NULL; - // return NULL; - // } - // arg->param1 = *pReq; - // arg->param2 = pThrd; - - // SDelayTask* task = transDQSched(pThrd->waitConnQueue, doFreeTimeoutMsg, arg, pInst->timeToGetConn); - // if (task == NULL) { - // taosMemoryFree(arg); - // doNotifyCb(*pReq, pThrd, TSDB_CODE_OUT_OF_MEMORY); - // *pReq = NULL; - // return NULL; - // } - - // (*pReq)->ctx->task = task; - // tGTrace("%s msg %s delay to send, wait for avaiable connect", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); - - // QUEUE_PUSH(&(list)->msgQ, &(*pReq)->q); - // queue* h = QUEUE_HEAD(&(list)->msgQ); - // QUEUE_REMOVE(h); - // SCliReq* ans = QUEUE_DATA(h, SCliReq, q); - - // *pReq = ans; - - // trace = &(*pReq)->msg.info.traceId; - // tGTrace("%s msg %s pop from delay queue, start to send", pInst->label, TMSG_INFO((*pReq)->msg.msgType)); - // transDQCancel(pThrd->waitConnQueue, ans->ctx->task); - // } - // list->numOfConn++; - // } - // tDebug("%s numOfConn: %d, limit: %d, dst:%s", pInst->label, list->numOfConn, pInst->connLimitNum, key); - // return NULL; - // } - - queue* h = QUEUE_TAIL(&plist->conns); - plist->size -= 1; - QUEUE_REMOVE(h); - - SCliConn* conn = QUEUE_DATA(h, SCliConn, q); - conn->status = ConnNormal; - QUEUE_INIT(&conn->q); - tDebug("conn %p get from pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); - if (conn->task != NULL) { - transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); - conn->task = NULL; - } - return conn; -} static void addConnToPool(void* pool, SCliConn* conn) { if (conn->status == ConnInPool) { return; @@ -919,34 +756,10 @@ static void addConnToPool(void* pool, SCliConn* conn) { SCliThrd* thrd = conn->hostThrd; cliResetConnTimer(conn); - if (TRANS_CONN_REF_GET(conn) > 1) { - transUnrefCliHandle(conn); - } - // cliDestroyConnMsgs(conn, false); - if (conn->list == NULL && conn->dstAddr != NULL) { conn->list = taosHashGet((SHashObj*)pool, conn->dstAddr, strlen(conn->dstAddr)); } - SConnList* pList = conn->list; - SMsgList* msgList = pList->list; - // if (!QUEUE_IS_EMPTY(&msgList->msgQ)) { - // queue* h = QUEUE_HEAD(&(msgList)->msgQ); - // QUEUE_REMOVE(h); - - // SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - - // transDQCancel(thrd->waitConnQueue, pReq->ctx->task); - // pReq->ctx->task = NULL; - - // transCtxMerge(&conn->ctx, &pReq->ctx->userCtx); - // (void)transQueuePush(&conn->reqsToSend, pReq); - - // conn->status = ConnNormal; - // (void)cliSend2(conn); - // return; - // } - conn->status = ConnInPool; QUEUE_PUSH(&conn->list->conns, &conn->q); conn->list->size += 1; @@ -998,30 +811,6 @@ static int32_t allocConnRef(SCliConn* conn, bool update) { return 0; } -static int32_t specifyConnRef(SCliConn* conn, bool update, int64_t handle) { - if (handle == 0) return -1; - if (update) { - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); - conn->refId = -1; - } - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle); - if (exh == NULL) { - return -1; - } - taosWLockLatch(&exh->latch); - exh->handle = conn; - exh->pThrd = conn->hostThrd; - taosWUnLockLatch(&exh->latch); - - conn->refId = exh->refId; - - tDebug("conn %p specified by %" PRId64 "", conn, 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; @@ -1040,17 +829,23 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { uv_fileno((uv_handle_t*)handle, &fd); setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int)); - SCliConn* conn = handle->data; + SCliConn* conn = handle->data; + int32_t ref = transUnrefCliHandle(conn); + if (ref <= 0) { + return; + } + SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { pBuf->len += nread; while (transReadComplete(pBuf)) { tTrace("%s conn %p read complete", CONN_GET_INST_LABEL(conn), conn); if (pBuf->invalid) { - return cliHandleBatch_shareConnExcept(conn); + transUnrefCliHandle(conn); + return; break; } else { - cliHandleResp2(conn); + cliHandleResp(conn); } } return; @@ -1064,10 +859,9 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { return; } if (nread < 0) { - tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), - TRANS_CONN_REF_GET(conn)); + tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), ref); conn->broken = true; - cliHandleExcept(conn, -1); + transUnrefCliHandle(conn); } } @@ -1151,8 +945,6 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int conn->stream->data = conn; conn->connReq.data = conn; - transRefCliHandle(conn); - *pCliConn = conn; return code; _failed: @@ -1173,47 +965,7 @@ _failed: taosMemoryFree(conn); return code; } -static void cliDestroyConn(SCliConn* conn, bool clear) { - SCliThrd* pThrd = conn->hostThrd; - tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn); - conn->broken = true; - QUEUE_REMOVE(&conn->q); - - conn->broken = true; - if (conn->list == NULL) { - conn->list = taosHashGet((SHashObj*)pThrd->pool, conn->dstAddr, strlen(conn->dstAddr)); - } - - if (conn->list) { - SConnList* list = conn->list; - list->list->numOfConn--; - if (conn->status == ConnInPool) { - list->size--; - } - } - conn->list = NULL; - - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); - conn->refId = -1; - - if (conn->task != NULL) { - transDQCancel(pThrd->timeoutQueue, conn->task); - conn->task = NULL; - } - - if (conn->pInitUserReq) { - taosMemoryFree(conn->pInitUserReq); - conn->pInitUserReq = NULL; - } - - if (clear) { - if (!uv_is_closing((uv_handle_t*)conn->stream)) { - (void)uv_read_stop(conn->stream); - uv_close((uv_handle_t*)conn->stream, cliDestroy); - } - } -} +static void cliDestroyConn(SCliConn* conn, bool clear) { cliHandleBatch_shareConnExcept(conn); } static void cliDestroy(uv_handle_t* handle) { if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) { return; @@ -1239,7 +991,6 @@ static void cliDestroy(uv_handle_t* handle) { tDebug("%s conn %p destroy state %ld", CONN_GET_INST_LABEL(conn), conn, *qid); } - // cliDestroyConnMsgs(conn, true); destroyCliConnQTable(conn); if (conn->pInitUserReq) { @@ -1283,7 +1034,6 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { if (pReq) { resp.info.traceId = pReq->msg.info.traceId; } - // resp.info.traceId = pReq ? pReq->msg.info.traceId : {0, 0}; // handle noresp and inter manage msg if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { @@ -1300,7 +1050,8 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { destroyReq(pReq); } } - if (!uv_is_closing((uv_handle_t*)conn->stream)) { + int8_t ref = transGetRefCount(conn); + if (ref == 0 && !uv_is_closing((uv_handle_t*)conn->stream)) { uv_close((uv_handle_t*)conn->stream, cliDestroy); } } @@ -1330,16 +1081,21 @@ static void cliConnRmReqs(SCliConn* conn) { static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { SCliConn* conn = req->data; SCliThrd* pThrd = conn->hostThrd; - conn->shareCnt -= 1; + + int32_t ref = transUnrefCliHandle(conn); + if (ref <= 0) { + taosMemoryFree(req); + return; + } cliConnRmReqs(conn); if (status != 0) { tDebug("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); - if (!uv_is_closing((uv_handle_t*)&conn->stream)) { - cliHandleBatch_shareConnExcept(conn); - } + transUnrefCliHandle(conn); return; } + + transRefCliHandle(conn); (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); taosMemoryFree(req); @@ -1442,9 +1198,9 @@ void cliSendBatch_shareConn(SCliConn* pConn) { return; } + transRefCliHandle(pConn); uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); req->data = pConn; - pConn->shareCnt += 1; tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliSendBatch_shareConnCb); taosMemoryFree(wb); @@ -1514,12 +1270,14 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { return code; } + transRefCliHandle(conn); ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { tError("failed connect to %s, reason:%s", conn->dstAddr, uv_err_name(ret)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); } + transRefCliHandle(conn); ret = uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); if (ret != 0) { tError("%s conn %p failed to start timer, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); @@ -1540,39 +1298,11 @@ _exception2: // cliResetConnTimer(conn); // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - // cliHandleFastFail(conn, code); // // taosMemoryFree(conn); return code; } -static void cliHandleFastFail_resp(SCliConn* pConn, int status) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pInst = pThrd->pInst; - // //kSCliReq* pReq = transQueueGet(&pConn->reqsToSend, 0); - - // STraceId* trace = &pReq->msg.info.traceId; - // tGError("%s msg %s failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), - // TMSG_INFO(pReq->msg.msgType), pConn, pConn->dstAddr, uv_strerror(status)); -} - -static void cliHandleFastFail_noresp(SCliConn* pConn, int status) { - tError("%s batch msg failed to send, conn %p failed to connect to %s, reason: %s", CONN_GET_INST_LABEL(pConn), pConn, - pConn->dstAddr, uv_strerror(status)); - cliDestroyBatch(pConn->pBatch); - pConn->pBatch = NULL; -} -static void cliHandleFastFail(SCliConn* pConn, int status) { - if (status == -1) status = UV_EADDRNOTAVAIL; - - if (pConn->pBatch == NULL) { - cliHandleFastFail_resp(pConn, status); - } else { - cliHandleFastFail_noresp(pConn, status); - } - cliHandleExcept(pConn, status); -} - int32_t cliConnSetSockInfo(SCliConn* pConn) { struct sockaddr peername, sockname; int addrlen = sizeof(peername); @@ -1593,20 +1323,20 @@ int32_t cliConnSetSockInfo(SCliConn* pConn) { return 0; }; -static int32_t cliBuildExeceptMsg(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { - SCliThrd* pThrd = pConn->hostThrd; - STrans* pInst = pThrd->pInst; - memset(pResp, 0, sizeof(STransMsg)); - STransMsg resp = {0}; - resp.contLen = 0; - resp.pCont = NULL; - resp.msgType = pReq->msg.msgType + 1; - resp.info.ahandle = pReq->ctx->ahandle; - resp.info.traceId = pReq->msg.info.traceId; - resp.info.hasEpSet = false; - resp.info.cliVer = pInst->compatibilityVer; - return 0; -} +// static int32_t cliBuildExeceptMsg(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { +// SCliThrd* pThrd = pConn->hostThrd; +// STrans* pInst = pThrd->pInst; +// memset(pResp, 0, sizeof(STransMsg)); +// STransMsg resp = {0}; +// resp.contLen = 0; +// resp.pCont = NULL; +// resp.msgType = pReq->msg.msgType + 1; +// resp.info.ahandle = pReq->ctx->ahandle; +// resp.info.traceId = pReq->msg.info.traceId; +// resp.info.hasEpSet = false; +// resp.info.cliVer = pInst->compatibilityVer; +// return 0; +// } bool filteGetAll(void* q, void* arg) { return true; } void cliConnCb(uv_connect_t* req, int status) { @@ -1614,8 +1344,13 @@ void cliConnCb(uv_connect_t* req, int status) { SCliThrd* pThrd = pConn->hostThrd; bool timeout = false; + int32_t ref = transUnrefCliHandle(pConn); + if (ref <= 0) { + return; + } if (pConn->timer == NULL) { timeout = true; + return; } else { cliResetConnTimer(pConn); } @@ -1625,14 +1360,11 @@ void cliConnCb(uv_connect_t* req, int status) { if (status != 0) { tDebug("%s conn %p failed to connect to %s, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, uv_strerror(status)); - cliHandleBatch_shareConnExcept(pConn); + transUnrefCliHandle(pConn); return; } pConn->connnected = 1; - cliConnSetSockInfo(pConn); - - // addConnToHeapCache(pThrd->connHeapCache, pConn); tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); (void)cliSend2(pConn); @@ -1676,68 +1408,9 @@ static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq) { (void)destroyConnPool(pThrd); (void)uv_walk(pThrd->loop, cliWalkCb, NULL); } -static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { - return; - // int64_t refId = (int64_t)(pReq->msg.info.handle); - // SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - // if (exh == NULL) { - // tDebug("%" PRId64 " already released", refId); - // destroyReq(pReq); - // return; - // } - - // taosRLockLatch(&exh->latch); - // SCliConn* conn = exh->handle; - // taosRUnLockLatch(&exh->latch); - - // (void)transReleaseExHandle(transGetRefMgt(), refId); - // tDebug("%s conn %p start to release to inst", CONN_GET_INST_LABEL(conn), conn); - - // if (TRANS_CONN_REF_GET(conn) == 2) { - // transUnrefCliHandle(conn); - // if (!transQueuePush(&conn->reqsToSend, &pReq->q)) { - // return; - // } - // (void)cliSend2(conn); - // } else { - // tError("%s conn %p already released", CONN_GET_INST_LABEL(conn), conn); - // destroyReq(pReq); - // } -} +static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { return; } static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { return; } -SCliConn* cliGetConn(SCliReq** pReq, SCliThrd* pThrd, bool* ignore, char* addr) { - SReqCtx* pCtx = (*pReq)->ctx; - SCliConn* conn = NULL; - - int64_t refId = (int64_t)((*pReq)->msg.info.handle); - if (refId != 0) { - SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); - if (exh == NULL) { - tError("failed to get conn, refId: %" PRId64 "", refId); - *ignore = true; - return NULL; - } else { - taosRLockLatch(&exh->latch); - conn = exh->handle; - taosRUnLockLatch(&exh->latch); - if (conn == NULL) { - conn = getConnFromPool2(pThrd, addr, pReq); - if (conn != NULL) specifyConnRef(conn, true, refId); - } - (void)transReleaseExHandle(transGetRefMgt(), refId); - } - return conn; - }; - - conn = getConnFromPool2(pThrd, addr, pReq); - if (conn != NULL) { - tTrace("%s conn %p get from conn pool:%p", CONN_GET_INST_LABEL(conn), conn, pThrd->pool); - } else { - tTrace("%s not found conn in conn pool:%p, dst:%s", ((STrans*)pThrd->pInst)->label, pThrd->pool, addr); - } - return conn; -} FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr) { if (pCvtAddr->cvt == false) { if (EPSET_IS_VALID(pEpSet)) { @@ -1775,19 +1448,19 @@ FORCE_INLINE int32_t cliBuildExceptResp(SCliReq* pReq, STransMsg* pResp) { return 0; } -FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliReq* pReq, int32_t code) { - STrans* pInst = pThrd->pInst; +// FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliReq* pReq, int32_t code) { +// STrans* pInst = pThrd->pInst; - STransMsg resp = {.code = code}; - code = cliBuildExceptResp(pReq, &resp); - if (code != 0) { - return code; - } - resp.info.cliVer = pInst->compatibilityVer; - pInst->cfp(pInst->parent, &resp, NULL); +// STransMsg resp = {.code = code}; +// code = cliBuildExceptResp(pReq, &resp); +// if (code != 0) { +// return code; +// } +// resp.info.cliVer = pInst->compatibilityVer; +// pInst->cfp(pInst->parent, &resp, NULL); - return 0; -} +// return 0; +// } static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ip) { int32_t code = 0; @@ -2130,39 +1803,7 @@ static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliReq* p *ppBatch = pBatch; return 0; } -static void cliDoBatchReq(queue* wq, SCliThrd* pThrd) { - STrans* pInst = pThrd->pInst; - int32_t code = 0; - - int count = 0; - while (!QUEUE_IS_EMPTY(wq)) { - queue* h = QUEUE_HEAD(wq); - QUEUE_REMOVE(h); - - SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - - // if (pReq->type == Normal && REQUEST_NO_RESP(&pReq->msg)) { - // cliBuildBatch(pReq, h, pThrd); - // continue; - // } - (*cliAsyncHandle[pReq->type])(pThrd, pReq); - count++; - } - - // void** pIter = taosHashIterate(pThrd->batchCache, NULL); - // while (pIter != NULL) { - // SCliBatchList* batchList = (SCliBatchList*)(*pIter); - // SCliBatch* batch = cliGetHeadFromList(batchList); - // if (batch != NULL) { - // cliHandleBatchReq(batch, pThrd); - // } - // pIter = (void**)taosHashIterate(pThrd->batchCache, pIter); - // } - - if (count >= 2) { - tTrace("cli process batch size:%d", count); - } -} +static void cliDoBatchReq(queue* wq, SCliThrd* pThrd) { return cliDoReq(wq, pThrd); } static void cliAsyncCb(uv_async_t* handle) { SAsyncItem* item = handle->data; @@ -2180,42 +1821,13 @@ static void cliAsyncCb(uv_async_t* handle) { if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd, pThrd->stopMsg); } -void cliDestroyConnMsgs(SCliConn* conn, bool destroy) { - // transCtxCleanup(&conn->ctx); - // cliReleaseUnfinishedMsg(conn); - if (destroy == 1) { - transQueueDestroy(&conn->reqsToSend); - } else { - transQueueClear(&conn->reqsToSend); - } - transQueueDestroy(&conn->reqsSentOut); -} - -void cliConnFreeMsgs(SCliConn* conn) { - SCliThrd* pThrd = conn->hostThrd; - STrans* pInst = pThrd->pInst; - - // for (int i = 0; i < transQueueSize(&conn->reqsToSend); i++) { - // SCliReq* cmsg = transQueueGet(&conn->reqsToSend, i); - // if (cmsg->type == Release || REQUEST_NO_RESP(&cmsg->msg) || cmsg->msg.msgType == TDMT_SCH_DROP_TASK) { - // continue; - // } - - // if (cliBuildExceptRespAndNotifyCb(pThrd, cmsg, 0) != 0) { - // continue; - // } - - // cmsg->ctx->ahandle = NULL; - // } -} - static FORCE_INLINE void destroyReq(void* arg) { SCliReq* pReq = arg; if (pReq == NULL) { return; } - - tDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); + STraceId* trace = &pReq->msg.info.traceId; + tGDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); if (pReq->ctx) destroyReqCtx(pReq->ctx); transFreeMsg(pReq->msg.pCont); @@ -2226,8 +1838,11 @@ static FORCE_INLINE void destroyReqWrapper(void* arg, void* param) { SCliReq* pReq = arg; SCliThrd* pThrd = param; - if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL) { - if (pThrd->destroyAhandleFp) (*pThrd->destroyAhandleFp)(pReq->msg.info.ahandle); + + if (pReq->ctx != NULL && pReq->ctx->ahandle != NULL) { + if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { + (*pThrd->destroyAhandleFp)(pReq->ctx->ahandle); + } } destroyReq(pReq); } @@ -2237,19 +1852,7 @@ static FORCE_INLINE void destroyReqAndAhanlde(void* param) { STaskArg* arg = param; SCliReq* pReq = arg->param1; SCliThrd* pThrd = arg->param2; - - if (pReq->msg.info.notFreeAhandle == 0 && pThrd != NULL && pThrd->destroyAhandleFp != NULL) { - pThrd->destroyAhandleFp(pReq->ctx->ahandle); - } - - if (pReq->msg.info.handle != 0) { - (void)transReleaseExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); - (void)transRemoveExHandle(transGetRefMgt(), (int64_t)pReq->msg.info.handle); - } - - destroyReqCtx(pReq->ctx); - transFreeMsg(pReq->msg.pCont); - taosMemoryFree(pReq); + destroyReqWrapper(pReq, pThrd); } static void* cliWorkThread(void* arg) { @@ -2404,11 +2007,6 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { 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); @@ -2566,7 +2164,14 @@ static FORCE_INLINE void doCloseIdleConn(void* param) { STaskArg* arg = param; SCliConn* conn = arg->param1; tDebug("%s conn %p idle, close it", CONN_GET_INST_LABEL(conn), conn); - conn->task = NULL; + + int32_t ref = transUnrefCliHandle(conn); + if (ref <= 0) { + conn->task = NULL; + taosMemoryFree(arg); + return; + } + cliDestroyConn(conn, true); taosMemoryFree(arg); } @@ -2945,17 +2550,26 @@ void transRefCliHandle(void* handle) { tTrace("%s conn %p ref %d", CONN_GET_INST_LABEL(conn), conn, conn->ref); } -void transUnrefCliHandle(void* handle) { +int32_t transUnrefCliHandle(void* handle) { if (handle == NULL) { - return; + return 0; } SCliConn* conn = (SCliConn*)handle; - conn->ref--; + int32_t ref = conn->ref--; tTrace("%s conn %p ref:%d", CONN_GET_INST_LABEL(conn), conn, conn->ref); if (conn->ref == 0) { cliDestroyConn(conn, true); } + return ref; +} + +int32_t transGetRefCount(void* handle) { + if (handle == NULL) { + return 0; + } + SCliConn* conn = (SCliConn*)handle; + return conn->ref; } static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t handle) { SCliThrd* pThrd = NULL; From 2c60ee27cc47890d1e5f2e8a1fcd232311f664ee Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 15:04:04 +0800 Subject: [PATCH 072/240] opt parameter --- source/libs/executor/src/exchangeoperator.c | 5 ++-- source/libs/transport/src/transCli.c | 31 +++++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 60faba3e3a..9e4c9cc071 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -528,9 +528,8 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { return TSDB_CODE_SUCCESS; } - int32_t index = pWrapper->sourceIndex; - int64_t* pRpcHandle = taosArrayGet(pExchangeInfo->pFetchRpcHandles, index); - *pRpcHandle = -1; + int32_t index = pWrapper->sourceIndex; + // int64_t* pRpcHandle = taosArrayGet(pExchangeInfo->pFetchRpcHandles, index); SSourceDataInfo* pSourceDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, index); if (!pSourceDataInfo) { return terrno; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 206253f9c2..500f75d4dd 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -607,6 +607,8 @@ void* destroyConnPool(SCliThrd* pThrd) { SCliConn* c = QUEUE_DATA(h, SCliConn, q); cliDestroyConn(c, true); } + SMsgList* msglist = connList->list; + taosMemoryFree(msglist); connList = taosHashIterate((SHashObj*)pool, connList); } @@ -1534,17 +1536,22 @@ static void doFreeTimeoutMsg(void* param) { } int32_t clConnMayUpdateReqCtx(SCliConn* pConn, SCliReq* pReq) { - int32_t code = 0; - int64_t qid = pReq->msg.info.qId; - SReqCtx* pCtx = pReq->ctx; + int32_t code = 0; + int64_t qid = pReq->msg.info.qId; + SReqCtx* pCtx = pReq->ctx; + SCliThrd* pThrd = pConn->hostThrd; + if (pCtx == NULL) { + tDebug("%s conn %p not need to update statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + return 0; + } STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (pUserCtx == NULL) { code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &pCtx->userCtx, sizeof(pCtx->userCtx)); - tDebug("succ to add conn %p of statue ctx, qid:%ld", pConn, qid); + tDebug("%s conn %p add conn %p of statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); } else { transCtxMerge(pUserCtx, &pCtx->userCtx); - tDebug("succ to update conn %p of statue ctx, qid:%ld", pConn, qid); + tDebug("%s conn %s update conn %p of statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); } return 0; } @@ -1576,11 +1583,6 @@ int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { if (qid == 0) { return TSDB_CODE_RPC_NO_STATE; } - SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); - if (pState != 0) { - tDebug("succ to get conn %p of statue, qid:%ld", pConn, qid); - ASSERT(0); - } SReqState state = {.conn = pConn, .arg = NULL}; code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); @@ -1915,6 +1917,9 @@ _err: } int32_t initCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = thrd; + if (pReq->ctx == NULL) { + return 0; + } return cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); } int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { @@ -3069,12 +3074,14 @@ int32_t transFreeConnById(void* pInstRef, int64_t transpointId) { } pCli->type = Normal; - tDebug("%s release conn id %" PRId64 "", pInst->label, transpointId); - STransMsg msg = {.msgType = TDMT_SCH_TASK_RELEASE, .info.handle = (void*)transpointId}; + TRACE_SET_MSGID(&msg.info.traceId, tGenIdPI64()); msg.info.qId = transpointId; pCli->msg = msg; + STraceId* trace = &pCli->msg.info.traceId; + tGDebug("%s start to free conn qid:%ld", pInst->label, transpointId); + code = transAsyncSend(pThrd->asyncPool, &pCli->q); if (code != 0) { taosMemoryFree(pCli); From a3c80a2a70ce78176c574021c32c6eb798188c8d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 15:14:15 +0800 Subject: [PATCH 073/240] opt parameter --- source/libs/transport/src/transSvr.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 30b9053979..7f22e944e0 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -443,11 +443,12 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { (void)taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); } - STransMsg tmsg = {.code = code, - .msgType = pHead->msgType + 1, - .info.qId = qId, - .info.traceId = pHead->traceId, - .info.seqNum = htonl(pHead->seqNum)}; + STransMsg tmsg = {.code = code, + .msgType = pHead->msgType + 1, + .info.qId = qId, + .info.traceId = pHead->traceId, + .info.seqNum = htonl(pHead->seqNum)}; + SSvrRespMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); srvMsg->msg = tmsg; srvMsg->type = Normal; @@ -456,6 +457,7 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { transQueuePush(&pConn->resps, &srvMsg->q); uvStartSendRespImpl(srvMsg); + taosMemoryFree(pHead); return 1; } return 0; @@ -507,6 +509,7 @@ static bool uvHandleReq(SSvrConn* pConn) { if (transDecompressMsg((char**)&pHead, msgLen) < 0) { tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); + taosMemoryFree(pHead); return false; } pHead->code = htonl(pHead->code); From 68c4af0e8a08263b40522b16c221da653e02b823 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 15:50:52 +0800 Subject: [PATCH 074/240] opt parameter --- source/libs/transport/src/transCli.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 500f75d4dd..fc262d2ec6 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -577,7 +577,6 @@ void cliHandleResp(SCliConn* conn) { if (cliMayRecycleConn(conn)) { return; } - transRefCliHandle(conn); (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } @@ -832,10 +831,6 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int)); SCliConn* conn = handle->data; - int32_t ref = transUnrefCliHandle(conn); - if (ref <= 0) { - return; - } SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { @@ -861,7 +856,8 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { return; } if (nread < 0) { - tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), ref); + tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), + transGetRefCount(conn)); conn->broken = true; transUnrefCliHandle(conn); } @@ -1097,7 +1093,6 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { return; } - transRefCliHandle(conn); (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); taosMemoryFree(req); @@ -1548,10 +1543,10 @@ int32_t clConnMayUpdateReqCtx(SCliConn* pConn, SCliReq* pReq) { STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (pUserCtx == NULL) { code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &pCtx->userCtx, sizeof(pCtx->userCtx)); - tDebug("%s conn %p add conn %p of statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p add statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); } else { transCtxMerge(pUserCtx, &pCtx->userCtx); - tDebug("%s conn %s update conn %p of statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %s update statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); } return 0; } @@ -1568,11 +1563,11 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { if (pReq->ctx == NULL) { return TSDB_CODE_RPC_STATE_DROPED; } - tDebug("failed to get statue, qid:%ld", qid); + tDebug("%s conn %p failed to get statue, qid:%ld", transLabel(pThrd->pInst), pConn, qid); return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { *pConn = pState->conn; - tDebug("succ to get conn of statue, qid:%ld", qid); + tDebug("%s conn %p succ to get conn of statue, qid:%ld", transLabel(pThrd->pInst), pConn, qid); } return 0; } @@ -1587,9 +1582,9 @@ int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { SReqState state = {.conn = pConn, .arg = NULL}; code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); if (code != 0) { - tDebug("failed to add conn %p of statue, qid:%ld", pConn, qid); + tDebug("%s conn %p failed to statue, qid:%ld", transLabel(pThrd->pInst), pConn, qid); } else { - tDebug("succ to add conn %p of statue, qid:%ld (1)", pConn, qid); + tDebug("%s conn %p succ to add statue, qid:%ld (1)", transLabel(pThrd->pInst), pConn, qid); } (void)clConnMayUpdateReqCtx(pConn, pReq); From 290c6f89df0b18d99a71ce494226e90e8edd3d8c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 16:08:20 +0800 Subject: [PATCH 075/240] opt parameter --- source/libs/transport/src/transSvr.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 7f22e944e0..028dc38194 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -434,13 +434,14 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); if (p == NULL) { code = TSDB_CODE_RPC_NO_STATE; - tTrace("conn %p recv release, and releady release by server qid%ld", pConn, qId); - // notify cli already release, cli release resouce + tTrace("conn %p recv release, and releady release by server qid:%ld", pConn, qId); } else { SSvrRegArg* arg = p; (pInst->cfp)(pInst->parent, &(arg->msg), NULL); - tTrace("conn %p recv release, notify server app, qid%ld", pConn, qId); + tTrace("conn %p recv release, notify server app, qid:%ld", pConn, qId); + (void)taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); + tTrace("conn %p clear state,qid:%ld", pConn, qId); } STransMsg tmsg = {.code = code, @@ -458,7 +459,7 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { uvStartSendRespImpl(srvMsg); taosMemoryFree(pHead); - return 1; + return code; } return 0; } @@ -501,6 +502,7 @@ static bool uvHandleReq(SSvrConn* pConn) { return false; } if (uvConnMayGetUserInfo(pConn, &pHead, &msgLen) == true) { + tDebug("%s conn %p get user info", transLabel(pInst), pConn); } if (resetBuf == 0) { @@ -833,7 +835,7 @@ int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE && qid > 0) { SSvrRegArg* p = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (p == NULL) { - tError("%s conn %p already release qid %ld", transLabel(pConn->pInst), pConn, qid); + tError("%s conn %p already release qid:%ld", transLabel(pConn->pInst), pConn, qid); return TSDB_CODE_RPC_NO_STATE; } else { transFreeMsg(p->msg.pCont); From 12b08ecc09146b404494c28e58f18c93a65d2a50 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 16:30:21 +0800 Subject: [PATCH 076/240] opt parameter --- source/libs/transport/src/transCli.c | 37 ++++++++++++++++------------ 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index fc262d2ec6..a7f3f2527c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -264,7 +264,7 @@ static FORCE_INLINE void destroyReqAndAhanlde(void* cmsg); static FORCE_INLINE int cliRBChoseIdx(STrans* pInst); static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx); -int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn); +int32_t cliHandleState_mayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn); int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); @@ -435,7 +435,7 @@ int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHe pResp->info.handle = (void*)qid; return 0; } -int32_t cliConnMayHandleState_releaseReq(SCliConn* conn, STransMsgHead* pHead) { +int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; if (pHead->msgType == TDMT_SCH_TASK_RELEASE || pHead->msgType == TDMT_SCH_TASK_RELEASE + 1) { @@ -480,7 +480,7 @@ int32_t cliConnMayHandleState_releaseReq(SCliConn* conn, STransMsgHead* pHead) { } return 0; } -int32_t cliMayHandleState(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp) { +int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp) { int32_t code = 0; int64_t qId = taosHton64(pHead->qid); if (qId == 0) { @@ -496,15 +496,20 @@ int32_t cliMayHandleState(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp TMSG_INFO(pHead->msgType)); return 0; } + +static FORCE_INLINE void cliConnClearInitUserMsg(SCliConn* conn) { + if (conn->pInitUserReq) { + taosMemoryFree(conn->pInitUserReq); + conn->pInitUserReq = NULL; + } +} void cliHandleResp(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - if (conn->pInitUserReq) { - taosMemoryFree(conn->pInitUserReq); - conn->pInitUserReq = NULL; - } + cliConnClearInitUserMsg(conn); + cliResetConnTimer(conn); SCliReq* pReq = NULL; @@ -529,7 +534,7 @@ void cliHandleResp(SCliConn* conn) { int32_t seq = htonl(pHead->seqNum); STransMsg resp = {0}; - if (cliConnMayHandleState_releaseReq(conn, pHead)) { + if (cliHandleState_mayHandleReleaseResp(conn, pHead)) { if (cliMayRecycleConn(conn)) { return; } @@ -537,7 +542,7 @@ void cliHandleResp(SCliConn* conn) { } code = cliGetReqBySeq(conn, seq, &pReq); if (code == TSDB_CODE_OUT_OF_RANGE) { - code = cliMayHandleState(conn, pHead, &resp); + code = cliHandleState_mayCreateAhandle(conn, pHead, &resp); if (code == 0) { code = cliBuildRespFromCont(NULL, &resp, pHead); code = cliNotifyCb(conn, NULL, &resp); @@ -871,7 +876,7 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); - code = cliMayUpdateState(pThrd, pReq, pConn); + code = cliHandleState_mayUpdateState(pThrd, pReq, pConn); addConnToHeapCache(pThrd->connHeapCache, pConn); transQueuePush(&pConn->reqsToSend, &pReq->q); @@ -1530,7 +1535,7 @@ static void doFreeTimeoutMsg(void* param) { taosMemoryFree(arg); } -int32_t clConnMayUpdateReqCtx(SCliConn* pConn, SCliReq* pReq) { +int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq) { int32_t code = 0; int64_t qid = pReq->msg.info.qId; SReqCtx* pCtx = pReq->ctx; @@ -1572,7 +1577,7 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { return 0; } -int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { +int32_t cliHandleState_mayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { int32_t code = 0; int64_t qid = pReq->msg.info.qId; if (qid == 0) { @@ -1587,7 +1592,7 @@ int32_t cliMayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { tDebug("%s conn %p succ to add statue, qid:%ld (1)", transLabel(pThrd->pInst), pConn, qid); } - (void)clConnMayUpdateReqCtx(pConn, pReq); + (void)cliHandleState_mayUpdateStateCtx(pConn, pReq); return code; } void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { @@ -1600,7 +1605,7 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { SCliConn* pConn = NULL; code = cliMayGetStateByQid(pThrd, pReq, &pConn); if (code == 0) { - (void)clConnMayUpdateReqCtx(pConn, pReq); + (void)cliHandleState_mayUpdateStateCtx(pConn, pReq); } else if (code == TSDB_CODE_RPC_STATE_DROPED) { STraceId* trace = &pReq->msg.info.traceId; tWarn("%s failed to get statue, qid:%ld", pInst->label, pReq->msg.info.qId); @@ -1627,7 +1632,7 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { addConnToHeapCache(pThrd->connHeapCache, pConn); } } - code = cliMayUpdateState(pThrd, pReq, pConn); + code = cliHandleState_mayUpdateState(pThrd, pReq, pConn); } code = cliSendReq(pConn, pReq); @@ -2017,7 +2022,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } - pThrd->pIdConnTable = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + pThrd->pIdConnTable = taosHashInit(512, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (pThrd->connHeapCache == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } From aa094def926fcf8ad5b70d8cb174f8f09617c6b0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 17:28:24 +0800 Subject: [PATCH 077/240] opt parameter --- source/libs/transport/src/transCli.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a7f3f2527c..0f06b8c0c2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3120,6 +3120,15 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea return code; } +static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentNum, int32_t stateNum) { + int32_t total = reqNum + sentNum + stateNum; + if (total >= 16) { + return 1; + } + + return 0; +} + static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int code = 0; SHeap* pHeap = NULL; @@ -3130,13 +3139,22 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } code = transHeapGet(pHeap, &pConn); + if (code != 0) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; } else { tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); - } + int32_t reqsNum = transQueueSize(&pConn->reqsToSend); + int32_t reqsSentOut = transQueueSize(&pConn->reqsSentOut); + int32_t stateNum = taosHashGetSize(pConn->pQTable); + if (shouldSWitchToOtherConn(reqsNum, reqsSentOut, stateNum)) { + tDebug("conn %p has %d reqs, %d sentout and %s status in process, switch to other conn", pConn, reqsNum, + reqsSentOut, stateNum); + return NULL; + } + } return pConn; } static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { From 8031f196ad2ae4cec9b2244c66489e070545494b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 21:09:00 +0800 Subject: [PATCH 078/240] opt parameter --- include/libs/transport/trpc.h | 1 + source/libs/transport/src/transSvr.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index c1265d768c..72e66e268f 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -66,6 +66,7 @@ typedef struct SRpcHandleInfo { int32_t seqNum; // msg seq int64_t qId; // queryId Get from client, other req's qId = -1; int32_t refIdMgt; + int32_t msgType; } SRpcHandleInfo; typedef struct SRpcMsg { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 028dc38194..45c18325b6 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -565,6 +565,7 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.info.noResp = pHead->noResp == 1 ? 1 : 0; transMsg.info.seqNum = htonl(pHead->seqNum); transMsg.info.qId = taosHton64(pHead->qid); + transMsg.info.msgType = pHead->msgType; // uvMaySetConnAcquired(pConn, pHead); @@ -1807,6 +1808,9 @@ int32_t transSendResponse(const STransMsg* msg) { STransMsg tmsg = *msg; tmsg.info.refId = refId; + if (tmsg.info.qId == 0) { + tmsg.msgType = msg->info.msgType + 1; + } SWorkThrd* pThrd = exh->pThrd; ASYNC_ERR_JRET(pThrd); @@ -1816,8 +1820,8 @@ int32_t transSendResponse(const STransMsg* msg) { code = TSDB_CODE_OUT_OF_MEMORY; goto _return1; } - m->msg = tmsg; + m->type = Normal; STraceId* trace = (STraceId*)&msg->info.traceId; From ff60d50cbc11b293f97d7dcb4b611c1f68d92091 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 21:21:34 +0800 Subject: [PATCH 079/240] fix invalid print --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 0f06b8c0c2..c38cca9f2c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3150,7 +3150,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int32_t stateNum = taosHashGetSize(pConn->pQTable); if (shouldSWitchToOtherConn(reqsNum, reqsSentOut, stateNum)) { - tDebug("conn %p has %d reqs, %d sentout and %s status in process, switch to other conn", pConn, reqsNum, + tDebug("conn %p has %d reqs, %d sentout and %d status in process, switch to other conn", pConn, reqsNum, reqsSentOut, stateNum); return NULL; } From 45bb65336c63c841eaf001231aec3a29f8afed45 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 14 Sep 2024 09:47:31 +0800 Subject: [PATCH 080/240] opt transport --- source/common/src/tglobal.c | 2 +- source/libs/transport/src/transCli.c | 60 +++++++++++++++------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 69171892cb..c69088bb24 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -601,7 +601,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { cfgAddInt64(pCfg, "randErrorDivisor", tsRandErrDivisor, 1, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "randErrorScope", tsRandErrScope, 0, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); - // tsNumOfRpcThreads = tsNumOfCores / 2; + tsNumOfRpcThreads = tsNumOfCores / 2; tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfRpcThreads", tsNumOfRpcThreads, 1, 1024, CFG_SCOPE_BOTH, CFG_DYN_NONE)); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c38cca9f2c..d7aab8357d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -231,9 +231,7 @@ static void cliDestroyBatch(SCliBatch* pBatch); static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx); static FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr); -static FORCE_INLINE int32_t cliBuildExceptResp(SCliReq* pReq, STransMsg* resp); - -// static FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliReq* pReq, int32_t code); +static FORCE_INLINE int32_t cliBuildExceptResp(SCliThrd* thrd, SCliReq* pReq, STransMsg* resp); static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ipaddr); static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn); @@ -519,6 +517,7 @@ void cliHandleResp(SCliConn* conn) { taosMemoryFree(pHead); tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb + ASSERT(0); pThrd->notifyExceptCb(pThrd, NULL, NULL); return; } @@ -1411,7 +1410,12 @@ static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq) { (void)uv_walk(pThrd->loop, cliWalkCb, NULL); } static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { return; } -static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { return; } +static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { + SReqCtx* pCtx = pReq->ctx; + pThrd->cvtAddr = pCtx->cvtAddr; + destroyReq(pReq); + return; +} FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr) { if (pCvtAddr->cvt == false) { @@ -1437,33 +1441,33 @@ FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx) { return transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet) ? false : true; } -FORCE_INLINE int32_t cliBuildExceptResp(SCliReq* pReq, STransMsg* pResp) { +FORCE_INLINE int32_t cliBuildExceptResp(SCliThrd* pThrd, SCliReq* pReq, STransMsg* pResp) { if (pReq == NULL) return -1; + STrans* pInst = pThrd->pInst; + + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; + STransMsg resp = {0}; + // resp.code = (conn->connnected ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL); + pResp->msgType = pReq ? pReq->msg.msgType + 1 : 0; + pResp->info.cliVer = pInst->compatibilityVer; + pResp->info.ahandle = pCtx ? pCtx->ahandle : 0; + if (pReq) { + pResp->info.traceId = pReq->msg.info.traceId; + } + + // handle noresp and inter manage msg + if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { + destroyReq(pReq); + return 0; + } if (pResp->code == 0) { pResp->code = TSDB_CODE_RPC_BROKEN_LINK; } - pResp->msgType = pReq->msg.msgType + 1; - pResp->info.ahandle = pReq->ctx ? pReq->ctx->ahandle : NULL; - pResp->info.traceId = pReq->msg.info.traceId; return 0; } -// FORCE_INLINE int32_t cliBuildExceptRespAndNotifyCb(SCliThrd* pThrd, SCliReq* pReq, int32_t code) { -// STrans* pInst = pThrd->pInst; - -// STransMsg resp = {.code = code}; -// code = cliBuildExceptResp(pReq, &resp); -// if (code != 0) { -// return code; -// } -// resp.info.cliVer = pInst->compatibilityVer; -// pInst->cfp(pInst->parent, &resp, NULL); - -// return 0; -// } - static FORCE_INLINE int32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn, uint32_t* ip) { int32_t code = 0; uint32_t addr = 0; @@ -1641,6 +1645,8 @@ void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { _exception: resp.code = code; + STraceId* trace = &pReq->msg.info.traceId; + tGWarn("%s failed to process req, reason:%s", pInst->label, tstrerror(code)); (void)(pThrd->notifyExceptCb)(pThrd, pReq, &resp); return; } @@ -1923,14 +1929,14 @@ int32_t initCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { return cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); } int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { - STrans* pInst = ((SCliThrd*)thrd)->pInst; - int32_t code = cliBuildExceptResp(pReq, pResp); - + SCliThrd* pThrd = thrd; + STrans* pInst = pThrd->pInst; + int32_t code = cliBuildExceptResp(pThrd, pReq, pResp); if (code != 0) { return code; } - pResp->info.cliVer = pInst->compatibilityVer; pInst->cfp(pInst->parent, pResp, NULL); + destroyReq(pReq); return code; } @@ -3122,7 +3128,7 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentNum, int32_t stateNum) { int32_t total = reqNum + sentNum + stateNum; - if (total >= 16) { + if (total >= 4) { return 1; } From 7dc3db8b389b9906ae3bfac877eeb973ccdaff70 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 14 Sep 2024 11:12:41 +0800 Subject: [PATCH 081/240] opt transport --- source/libs/transport/src/transCli.c | 163 +++++++++++---------------- 1 file changed, 68 insertions(+), 95 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d7aab8357d..db444bb078 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -25,9 +25,8 @@ typedef struct { } SMsgList; typedef struct SConnList { - queue conns; - int32_t size; - SMsgList* list; + queue conns; + int32_t size; } SConnList; typedef struct { @@ -180,18 +179,18 @@ typedef struct { // conn pool // add expire timeout and capacity limit -static void* createConnPool(int size); -static void* destroyConnPool(SCliThrd* thread); -static SCliConn* getConnFromPool(SCliThrd* thread, char* key, bool* exceed); -static void addConnToPool(void* pool, SCliConn* conn); -static void doCloseIdleConn(void* param); -static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); -static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int port); -static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn); -static void cliSendBatch_shareConnCb(uv_write_t* req, int status); -void cliSendBatch_shareConn(SCliConn* pConn); -int32_t cliSend2(SCliConn* conn); -bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead); +static void* createConnPool(int size); +static void* destroyConnPool(SCliThrd* thread); +// static SCliConn* getConnFromPool(SCliThrd* thread, char* key, bool* exceed); +static void addConnToPool(void* pool, SCliConn* conn); +static void doCloseIdleConn(void* param); +static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); +static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int port); +static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn); +static void cliBatchSendCb(uv_write_t* req, int status); +void cliBatchSendImpl(SCliConn* pConn); +static int32_t cliBatchSend(SCliConn* conn); +bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead); // register conn timer static void cliConnTimeout(uv_timer_t* handle); // register timer for read @@ -207,7 +206,6 @@ static void cliRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf); // callback after conn to server static void cliConnCb(uv_connect_t* req, int status); static void cliAsyncCb(uv_async_t* handle); -static void cliSendBatchCb(uv_write_t* req, int status); SCliBatch* cliGetHeadFromList(SCliBatchList* pList); @@ -574,7 +572,6 @@ void cliHandleResp(SCliConn* conn) { if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { STraceId* trace = &resp.info.traceId; tGWarn("%s msg need retry", CONN_GET_INST_LABEL(conn)); - // retry, notify } else { destroyReq(pReq); } @@ -610,9 +607,6 @@ void* destroyConnPool(SCliThrd* pThrd) { SCliConn* c = QUEUE_DATA(h, SCliConn, q); cliDestroyConn(c, true); } - SMsgList* msglist = connList->list; - taosMemoryFree(msglist); - connList = taosHashIterate((SHashObj*)pool, connList); } taosHashCleanup(pool); @@ -620,57 +614,58 @@ void* destroyConnPool(SCliThrd* pThrd) { return NULL; } -static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) { - void* pool = pThrd->pool; - STrans* pTranInst = pThrd->pInst; - size_t klen = strlen(key); - SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); - if (plist == NULL) { - SConnList list = {0}; - (void)taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); - plist = taosHashGet(pool, key, klen); +// static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) { +// void* pool = pThrd->pool; +// STrans* pTranInst = pThrd->pInst; +// size_t klen = strlen(key); +// SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); +// if (plist == NULL) { +// SConnList list = {0}; +// (void)taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); +// plist = taosHashGet(pool, key, klen); - SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); - QUEUE_INIT(&nList->msgQ); - nList->numOfConn++; +// // SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); +// // QUEUE_INIT(&nList->msgQ); +// // nList->numOfConn++; - QUEUE_INIT(&plist->conns); - plist->list = nList; - } +// QUEUE_INIT(&plist->conns); +// //plist->list = nList; +// } - if (QUEUE_IS_EMPTY(&plist->conns)) { - if (plist->list->numOfConn >= pTranInst->connLimitNum) { - *exceed = true; - return NULL; - } - plist->list->numOfConn++; - return NULL; - } +// if (QUEUE_IS_EMPTY(&plist->conns)) { +// if (plist->list->numOfConn >= pTranInst->connLimitNum) { +// *exceed = true; +// return NULL; +// } +// plist->list->numOfConn++; +// return NULL; +// } - queue* h = QUEUE_TAIL(&plist->conns); - QUEUE_REMOVE(h); - plist->size -= 1; +// queue* h = QUEUE_TAIL(&plist->conns); +// QUEUE_REMOVE(h); +// plist->size -= 1; - SCliConn* conn = QUEUE_DATA(h, SCliConn, q); - conn->status = ConnNormal; - QUEUE_INIT(&conn->q); - tDebug("conn %p get from pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); +// SCliConn* conn = QUEUE_DATA(h, SCliConn, q); +// conn->status = ConnNormal; +// QUEUE_INIT(&conn->q); +// tDebug("conn %p get from pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); - if (conn->task != NULL) { - transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); - conn->task = NULL; - } - conn->seq++; - return conn; -} +// if (conn->task != NULL) { +// transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); +// conn->task = NULL; +// } +// conn->seq++; +// return conn; +// } -static int32_t getOrCreateMsgList(SCliThrd* pThrd, const char* key, SConnList** ppList) { +static int32_t getOrCreateConnList(SCliThrd* pThrd, const char* key, SConnList** ppList) { int32_t code = 0; void* pool = pThrd->pool; size_t klen = strlen(key); SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); if (plist == NULL) { SConnList list = {0}; + QUEUE_INIT(&list.conns); code = taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); if (code != 0) { return code; @@ -680,16 +675,7 @@ static int32_t getOrCreateMsgList(SCliThrd* pThrd, const char* key, SConnList** if (plist == NULL) { return TSDB_CODE_INVALID_PTR; } - - SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); - if (nList == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - QUEUE_INIT(&nList->msgQ); - nList->numOfConn++; - QUEUE_INIT(&plist->conns); - plist->list = nList; *ppList = plist; } else { *ppList = plist; @@ -702,13 +688,13 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p STrans* pInst = pThrd->pInst; SConnList* plist = NULL; - code = getOrCreateMsgList(pThrd, key, &plist); + code = getOrCreateConnList(pThrd, key, &plist); if (code != 0) { return code; } if (QUEUE_IS_EMPTY(&plist->conns)) { - if (plist->list->numOfConn >= pInst->connLimitNum) { + if (plist->size >= pInst->connLimitNum) { return TSDB_CODE_RPC_MAX_SESSIONS; } return TSDB_CODE_RPC_NETWORK_BUSY; @@ -721,6 +707,8 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p SCliConn* conn = QUEUE_DATA(h, SCliConn, q); conn->status = ConnNormal; QUEUE_INIT(&conn->q); + conn->seq = 0; + conn->list = plist; if (conn->task != NULL) { SDelayTask* task = conn->task; @@ -756,7 +744,6 @@ static void addConnToPool(void* pool, SCliConn* conn) { return; } uv_read_stop(conn->stream); - conn->seq = 0; SCliThrd* thrd = conn->hostThrd; @@ -1080,7 +1067,7 @@ static void cliConnRmReqs(SCliConn* conn) { return; } -static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { +static void cliBatchSendCb(uv_write_t* req, int status) { SCliConn* conn = req->data; SCliThrd* pThrd = conn->hostThrd; @@ -1101,7 +1088,7 @@ static void cliSendBatch_shareConnCb(uv_write_t* req, int status) { taosMemoryFree(req); if (!cliMayRecycleConn(conn)) { - cliSendBatch_shareConn(conn); + cliBatchSend(conn); } } bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msgLen) { @@ -1126,7 +1113,7 @@ bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msg pConn->userInited = 1; return true; } -void cliSendBatch_shareConn(SCliConn* pConn) { +int32_t cliBatchSend(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; int32_t size = transQueueSize(&pConn->reqsToSend); @@ -1134,7 +1121,7 @@ void cliSendBatch_shareConn(SCliConn* pConn) { int32_t totalLen = 0; if (size == 0) { tDebug("%s conn %p not msg to send", pInst->label, pConn); - return; + return 0; } uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); @@ -1191,38 +1178,25 @@ void cliSendBatch_shareConn(SCliConn* pConn) { STraceId* trace = &pCliMsg->msg.info.traceId; tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d, qid:%ld", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); - transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); } - if (j == 0) { - taosMemoryFree(wb); - return; - } transRefCliHandle(pConn); uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); req->data = pConn; tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); - uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliSendBatch_shareConnCb); + uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); taosMemoryFree(wb); + return 0; } int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; transQueuePush(&pConn->reqsToSend, &pCliMsg->q); - if (pConn->connnected) { - code = cliSend2(pConn); - } else { - // do nothing - } + code = cliBatchSend(pConn); return code; } -int32_t cliSend2(SCliConn* pConn) { - cliSendBatch_shareConn(pConn); - return 0; -} - static void cliDestroyBatch(SCliBatch* pBatch) { if (pBatch == NULL) return; while (!QUEUE_IS_EMPTY(&pBatch->wq)) { @@ -1368,7 +1342,7 @@ void cliConnCb(uv_connect_t* req, int status) { cliConnSetSockInfo(pConn); tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); - (void)cliSend2(pConn); + (void)cliBatchSend(pConn); } static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code) { @@ -1599,7 +1573,7 @@ int32_t cliHandleState_mayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* (void)cliHandleState_mayUpdateStateCtx(pConn, pReq); return code; } -void cliHandleReq__noShareConn(SCliThrd* pThrd, SCliReq* pReq) { +void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { int32_t lino = 0; STransMsg resp = {0}; int32_t code = (pThrd->initCb)(pThrd, pReq, NULL); @@ -1651,7 +1625,7 @@ _exception: return; } -void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq) { return cliHandleReq__noShareConn(pThrd, pReq); } +void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq) { return cliHandleBatchReq(pThrd, pReq); } static void cliDoReq(queue* wq, SCliThrd* pThrd) { int count = 0; @@ -2182,8 +2156,6 @@ static FORCE_INLINE void doCloseIdleConn(void* param) { taosMemoryFree(arg); return; } - - cliDestroyConn(conn, true); taosMemoryFree(arg); } static FORCE_INLINE void cliPerfLog_schedMsg(SCliReq* pReq, char* label) { @@ -2440,6 +2412,7 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { cliRetryUpdateRule(pCtx, noDelay); pReq->sent = 0; + pReq->seq = 0; code = cliRetryDoSched(pReq, pThrd); if (code != 0) { From 6524367f85237db772f1ccbe3326ff88c1dc9b40 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 14 Sep 2024 11:25:29 +0800 Subject: [PATCH 082/240] opt transport --- source/libs/transport/src/transSvr.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 45c18325b6..bf54c04d9b 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -385,7 +385,6 @@ static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* static int64_t EXCEPTION_LIMIT_US = 100 * 1000; if (pConn->status == ConnNormal && pHead->noResp == 0) { - // transRefSrvHandle(pConn); if (cost >= EXCEPTION_LIMIT_US) { tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception, seqNum:%d, qid:%ld", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, @@ -607,7 +606,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { if (true == pBuf->invalid || false == uvHandleReq(conn)) { tError("%s conn %p read invalid packet, received from %s, local info:%s", transLabel(pInst), conn, conn->dst, conn->src); - destroyConn(conn, true); + transUnrefCliHandle(conn); return; } } @@ -615,7 +614,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { } else { tError("%s conn %p read invalid packet, exceed limit, received from %s, local info:%s", transLabel(pInst), conn, conn->dst, conn->src); - destroyConn(conn, true); + transUnrefCliHandle(conn); return; } } @@ -626,15 +625,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { tDebug("%s conn %p read error:%s", transLabel(pInst), conn, uv_err_name(nread)); if (nread < 0) { conn->broken = true; - // if (conn->status == ConnAcquire) { - // if (conn->regArg.init) { - // tTrace("%s conn %p broken, notify server app", transLabel(pInst), conn); - // STrans* pInst = conn->pInst; - // (*pInst->cfp)(pInst->parent, &(conn->regArg.msg), NULL); - // memset(&conn->regArg, 0, sizeof(conn->regArg)); - // } - // } - destroyConn(conn, true); + transUnrefCliHandle(conn); } } void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { @@ -682,10 +673,8 @@ void uvOnSendCb(uv_write_t* req, int status) { destroySmsg(smsg); } - if (!uv_is_closing((uv_handle_t*)(conn->pTcp))) { - tError("conn %p failed to write data, %s", conn, uv_err_name(status)); - conn->broken = true; - } + conn->broken = true; + transUnrefCliHandle(conn); } taosMemoryFree(userReq); transUnrefSrvHandle(conn); From 76cb30080fc6cdb678e7257ec68d2dde1bcdaabe Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 14 Sep 2024 11:42:27 +0800 Subject: [PATCH 083/240] opt transport --- source/libs/transport/src/transSvr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index bf54c04d9b..991290a1bb 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -606,7 +606,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { if (true == pBuf->invalid || false == uvHandleReq(conn)) { tError("%s conn %p read invalid packet, received from %s, local info:%s", transLabel(pInst), conn, conn->dst, conn->src); - transUnrefCliHandle(conn); + transUnrefSrvHandle(conn); return; } } @@ -614,7 +614,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { } else { tError("%s conn %p read invalid packet, exceed limit, received from %s, local info:%s", transLabel(pInst), conn, conn->dst, conn->src); - transUnrefCliHandle(conn); + transUnrefSrvHandle(conn); return; } } @@ -625,7 +625,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { tDebug("%s conn %p read error:%s", transLabel(pInst), conn, uv_err_name(nread)); if (nread < 0) { conn->broken = true; - transUnrefCliHandle(conn); + transUnrefSrvHandle(conn); } } void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { @@ -674,7 +674,7 @@ void uvOnSendCb(uv_write_t* req, int status) { } conn->broken = true; - transUnrefCliHandle(conn); + transUnrefSrvHandle(conn); } taosMemoryFree(userReq); transUnrefSrvHandle(conn); From 80aaa07b269c89f081c9cedc22521172c16a88a0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 14 Sep 2024 14:37:16 +0800 Subject: [PATCH 084/240] opt transport --- source/common/src/tglobal.c | 1 - source/libs/transport/inc/transComm.h | 13 +++++ source/libs/transport/src/transCli.c | 71 +++++++++++++++++++++------ source/libs/transport/src/transSvr.c | 42 +++++++++++++--- 4 files changed, 102 insertions(+), 25 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index c69088bb24..38f3edeb98 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -864,7 +864,6 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem = cfgGetItem(pCfg, "numOfRpcThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - // tsNumOfRpcThreads = numOfCores / 2; tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); pItem->i32 = tsNumOfRpcThreads; pItem->stype = stype; diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index a0695bb5d3..febc349e41 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -496,6 +496,19 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pWhiteList, char** ppBuf); enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; +#define BUFFER_LIMIT 8 + +typedef struct { + queue q; + uv_write_t wreq; + void* arg; +} SWReqsWrapper; + +int32_t initWQ(queue* wq); +void destroyWQ(queue* wq); +uv_write_t* allocWReqFromWQ(queue* wq, void* arg); + +void freeWReqToWQ(queue* wq, SWReqsWrapper* w); #ifdef __cplusplus } #endif diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index db444bb078..8d76a419ef 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -100,6 +100,13 @@ typedef struct SCliConn { SHashObj* pQTable; int8_t userInited; void* pInitUserReq; + + void* heap; // point to req conn heap + + uv_buf_t* buf; + int32_t bufSize; + + queue wq; // uv_write_t queue } SCliConn; // #define TRANS_CONN_REF_INC(tconn) ((tconn) ? (tconn)->ref++ : 0) @@ -744,7 +751,6 @@ static void addConnToPool(void* pool, SCliConn* conn) { return; } uv_read_stop(conn->stream); - conn->seq = 0; SCliThrd* thrd = conn->hostThrd; cliResetConnTimer(conn); @@ -757,6 +763,9 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->list->size += 1; tDebug("conn %p added to pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); + conn->heap = NULL; + conn->seq = 0; + if (conn->list->size >= 10) { STaskArg* arg = taosMemoryCalloc(1, sizeof(STaskArg)); if (arg == NULL) return; @@ -931,10 +940,16 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int code = TSDB_CODE_THIRDPARTY_ERROR; TAOS_CHECK_GOTO(code, NULL, _failed); } + + conn->bufSize = BUFFER_LIMIT; + conn->buf = (uv_buf_t*)taosMemoryCalloc(1, BUFFER_LIMIT * sizeof(uv_buf_t)); + + initWQ(&conn->wq); conn->stream->data = conn; conn->connReq.data = conn; *pCliConn = conn; + return code; _failed: if (conn) { @@ -986,6 +1001,11 @@ static void cliDestroy(uv_handle_t* handle) { taosMemoryFree(conn->pInitUserReq); conn->pInitUserReq = NULL; } + + taosMemoryFree(conn->buf); + + destroyWQ(&conn->wq); + tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); transReqQueueClear(&conn->wreqQueue); (void)transDestroyBuffer(&conn->readBuf); @@ -1068,12 +1088,15 @@ static void cliConnRmReqs(SCliConn* conn) { } static void cliBatchSendCb(uv_write_t* req, int status) { - SCliConn* conn = req->data; + SWReqsWrapper* wrapper = (SWReqsWrapper*)req->data; + SCliConn* conn = wrapper->arg; + SCliThrd* pThrd = conn->hostThrd; + freeWReqToWQ(&conn->wq, wrapper); + int32_t ref = transUnrefCliHandle(conn); if (ref <= 0) { - taosMemoryFree(req); return; } @@ -1085,7 +1108,6 @@ static void cliBatchSendCb(uv_write_t* req, int status) { } (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); - taosMemoryFree(req); if (!cliMayRecycleConn(conn)) { cliBatchSend(conn); @@ -1123,7 +1145,15 @@ int32_t cliBatchSend(SCliConn* pConn) { tDebug("%s conn %p not msg to send", pInst->label, pConn); return 0; } - uv_buf_t* wb = taosMemoryCalloc(size, sizeof(uv_buf_t)); + uv_buf_t* wb = NULL; + if (pConn->bufSize < size) { + pConn->buf = taosMemoryRealloc(pConn->buf, size * sizeof(uv_buf_t)); + pConn->bufSize = size; + taosMemoryFree(wb); + return TSDB_CODE_OUT_OF_MEMORY; + } + + wb = pConn->buf; int j = 0; while (!transQueueEmpty(&pConn->reqsToSend)) { @@ -1182,11 +1212,9 @@ int32_t cliBatchSend(SCliConn* pConn) { } transRefCliHandle(pConn); - uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); - req->data = pConn; + uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); - taosMemoryFree(wb); return 0; } @@ -1526,10 +1554,10 @@ int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq) { STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (pUserCtx == NULL) { code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &pCtx->userCtx, sizeof(pCtx->userCtx)); - tDebug("%s conn %p add statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to add statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); } else { transCtxMerge(pUserCtx, &pCtx->userCtx); - tDebug("%s conn %s update statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %s succ to update statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); } return 0; } @@ -2561,7 +2589,7 @@ static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t if (exh == NULL) { return NULL; } else { - tDebug("conn %p got", exh->handle); + tDebug("%s conn %p got", trans->label, exh->handle); } taosWLockLatch(&exh->latch); if (exh->pThrd == NULL && trans != NULL) { @@ -3118,7 +3146,6 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } code = transHeapGet(pHeap, &pConn); - if (code != 0) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; @@ -3137,12 +3164,18 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return pConn; } static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { - SHeap* p = NULL; + SHeap* p = NULL; + int32_t code = 0; - int32_t code = getOrCreateHeap(pConnHeapCacahe, pConn->dstAddr, &p); - if (code != 0) { - return code; + if (pConn->heap != NULL) { + p = pConn->heap; + } else { + code = getOrCreateHeap(pConnHeapCacahe, pConn->dstAddr, &p); + if (code != 0) { + return code; + } } + code = transHeapInsert(p, pConn); tDebug("add conn %p to heap cache for key:%s,status:%d, refCnt:%d", pConn, pConn->dstAddr, pConn->inHeap, pConn->reqRefCnt); @@ -3150,6 +3183,10 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { } static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { + if (pConn->heap != NULL) { + return transHeapDelete(pConn->heap, pConn); + } + SHeap* p = taosHashGet(pConnHeapCache, pConn->dstAddr, strlen(pConn->dstAddr)); if (p == NULL) { tDebug("failed to get heap cache for key:%s, no need to del", pConn->dstAddr); @@ -3207,6 +3244,7 @@ int32_t transHeapInsert(SHeap* heap, SCliConn* p) { heapInsert(heap->heap, &p->node); p->inHeap = 1; + p->heap = heap; return 0; } int32_t transHeapDelete(SHeap* heap, SCliConn* p) { @@ -3219,6 +3257,7 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { p->reqRefCnt--; if (p->reqRefCnt == 0) { heapRemove(heap->heap, &p->node); + p->heap = NULL; tDebug("delete conn %p delete from heap", p); } else if (p->reqRefCnt < 0) { tDebug("conn %p has %d reqs, not delete from heap,assert", p, p->reqRefCnt); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 991290a1bb..a4f5dd17bf 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -62,6 +62,9 @@ typedef struct SSvrConn { // state req dict SHashObj* pQTable; + uv_buf_t* buf; + int32_t bufSize; + queue wq; // uv_write_t queue } SSvrConn; typedef struct SSvrRespMsg { @@ -645,10 +648,14 @@ void uvOnTimeoutCb(uv_timer_t* handle) { void uvOnSendCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); - SWriteReq* userReq = req->data; + SWReqsWrapper* wrapper = req->data; + + SWriteReq* userReq = wrapper->arg; SSvrConn* conn = userReq->conn; queue* src = &userReq->node; + freeWReqToWQ(&conn->wq, wrapper); + tDebug("%s conn %p send data out ", transLabel(conn->pInst), conn); if (status == 0) { while (!QUEUE_IS_EMPTY(src)) { @@ -752,12 +759,14 @@ static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* buf if (size == 0) { return 0; } - int32_t count = 0; - uv_buf_t* pWb = taosMemoryCalloc(size, sizeof(uv_buf_t)); - if (pWb == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + if (pConn->bufSize < size) { + pConn->buf = taosMemoryRealloc(pConn->buf, size * sizeof(uv_buf_t)); + pConn->bufSize = size; } + uv_buf_t* pWb = pConn->buf; + + int32_t count = 0; while (transQueueSize(&pConn->resps) > 0) { queue* el = transQueuePop(&pConn->resps); @@ -787,11 +796,17 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { if (pConn->broken) { return; } + int32_t size = transQueueSize(&pConn->resps); + if (size == 0) { + tDebug("%s conn %p has %d msg to send", transLabel(pConn->pInst), pConn, size); + return; + } SWriteReq* pWreq = taosMemoryCalloc(1, sizeof(SWriteReq)); pWreq->conn = pConn; QUEUE_INIT(&pWreq->node); - pWreq->req.data = pWreq; + + uv_write_t* req = allocWReqFromWQ(&pConn->wq, pWreq); uv_buf_t* pBuf = NULL; int32_t bufNum = 0; @@ -807,17 +822,17 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { transRefSrvHandle(pConn); - uv_write_t* req = &pWreq->req; if (req == NULL) { if (!uv_is_closing((uv_handle_t*)(pConn->pTcp))) { tError("conn %p failed to write data, reason:%s", pConn, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); pConn->broken = true; + freeWReqToWQ(&pConn->wq, req->data); + taosMemoryFree(pWreq); transUnrefSrvHandle(pConn); return; } } (void)uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); - taosMemoryFree(pBuf); } int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { SSvrConn* pConn = pMsg->pConn; @@ -1258,12 +1273,18 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); } + code = initWQ(&pConn->wq); + TAOS_CHECK_GOTO(code, &lino, _end); + // 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, &lino, _end); } + pConn->bufSize = BUFFER_LIMIT; + pConn->buf = taosMemoryCalloc(1, sizeof(uv_buf_t)); + code = uv_tcp_init(pThrd->loop, pConn->pTcp); if (code != 0) { tError("%s failed to create conn since %s" PRId64, transLabel(pInst), uv_strerror(code)); @@ -1282,6 +1303,8 @@ _end: (void)transDestroyBuffer(&pConn->readBuf); taosHashCleanup(pConn->pQTable); taosMemoryFree(pConn->pTcp); + destroyWQ(&pConn->wq); + taosMemoryFree(pConn->buf); taosMemoryFree(pConn); pConn = NULL; } @@ -1345,6 +1368,9 @@ static void uvDestroyConn(uv_handle_t* handle) { uvConnDestroyAllState(conn); (void)transDestroyBuffer(&conn->readBuf); + + destroyWQ(&conn->wq); + taosMemoryFree(conn->buf); taosMemoryFree(conn); if (thrd->quit && QUEUE_IS_EMPTY(&thrd->conn)) { From 8902f78f509b229ee8aaffa1e83be1eb3eae994f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 14 Sep 2024 15:18:13 +0800 Subject: [PATCH 085/240] opt parameter --- source/libs/transport/inc/transComm.h | 6 +-- source/libs/transport/src/transCli.c | 4 -- source/libs/transport/src/transComm.c | 71 +++++++++++++++++++++------ source/libs/transport/src/transSvr.c | 3 -- 4 files changed, 57 insertions(+), 27 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index febc349e41..4bf62f2067 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -349,10 +349,8 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType); // request list typedef struct SWriteReq { - queue q; // gloabl queue node - queue node; // req queue node - void* conn; - uv_write_t req; + queue node; // req queue node + void* conn; } SWriteReq; void transReqQueueInit(queue* q); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 8d76a419ef..f8328c5b69 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -57,7 +57,6 @@ typedef struct SCliConn { int32_t ref; uv_connect_t connReq; uv_stream_t* stream; - queue wreqQueue; uv_timer_t* timer; // read timer, forbidden @@ -909,8 +908,6 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int conn->broken = false; QUEUE_INIT(&conn->q); - transReqQueueInit(&conn->wreqQueue); - TAOS_CHECK_GOTO(transQueueInit(&conn->reqsToSend, cliDestroyMsg), NULL, _failed); TAOS_CHECK_GOTO(transQueueInit(&conn->reqsSentOut, cliDestroyMsg), NULL, _failed); @@ -1007,7 +1004,6 @@ static void cliDestroy(uv_handle_t* handle) { destroyWQ(&conn->wq); tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); - transReqQueueClear(&conn->wreqQueue); (void)transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 951b651ee1..7814ccafac 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -412,29 +412,32 @@ void transReqQueueInit(queue* q) { QUEUE_INIT(q); } void* transReqQueuePush(queue* q, SWriteReq* userReq) { - uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); - req->data = userReq; + return NULL; + // uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); + // req->data = userReq; - QUEUE_PUSH(q, &userReq->q); - return req; + // QUEUE_PUSH(q, &userReq->q); + // return req; } void* transReqQueueRemove(void* arg) { - void* ret = NULL; - uv_write_t* req = arg; + return NULL; + // void* ret = NULL; + // uv_write_t* req = arg; - SWriteReq* userReq = req ? req->data : NULL; - if (req == NULL) return NULL; - QUEUE_REMOVE(&userReq->q); + // SWriteReq* userReq = req ? req->data : NULL; + // if (req == NULL) return NULL; + // QUEUE_REMOVE(&userReq->q); - return userReq; + // return userReq; } void transReqQueueClear(queue* q) { - while (!QUEUE_IS_EMPTY(q)) { - queue* h = QUEUE_HEAD(q); - QUEUE_REMOVE(h); - SWriteReq* req = QUEUE_DATA(h, SWriteReq, q); - taosMemoryFree(req); - } + return; + // while (!QUEUE_IS_EMPTY(q)) { + // queue* h = QUEUE_HEAD(q); + // QUEUE_REMOVE(h); + // SWriteReq* req = QUEUE_DATA(h, SWriteReq, q); + // taosMemoryFree(req); + // } } int32_t transQueueInit(STransQueue* wq, void (*freeFunc)(void* arg)) { @@ -883,3 +886,39 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) { // STUB_RAND_NETWORK_ERR(status) // return status; // } + +int32_t initWQ(queue* wq) { + QUEUE_INIT(wq); + for (int i = 0; i < 4; i++) { + SWReqsWrapper* w = taosMemoryCalloc(1, sizeof(SWReqsWrapper)); + w->wreq.data = w; + w->arg = NULL; + QUEUE_PUSH(wq, &w->q); + } + return 0; +} +void destroyWQ(queue* wq) { + while (!QUEUE_IS_EMPTY(wq)) { + queue* h = QUEUE_HEAD(wq); + QUEUE_REMOVE(h); + SWReqsWrapper* w = QUEUE_DATA(h, SWReqsWrapper, q); + taosMemoryFree(w); + } +} + +uv_write_t* allocWReqFromWQ(queue* wq, void* arg) { + if (!QUEUE_IS_EMPTY(wq)) { + queue* node = QUEUE_HEAD(wq); + QUEUE_REMOVE(node); + SWReqsWrapper* w = QUEUE_DATA(node, SWReqsWrapper, q); + w->arg = arg; + return &w->wreq; + } else { + SWReqsWrapper* w = taosMemoryCalloc(1, sizeof(SWReqsWrapper)); + w->wreq.data = w; + w->arg = arg; + return &w->wreq; + } +} + +void freeWReqToWQ(queue* wq, SWReqsWrapper* w) { QUEUE_PUSH(wq, &w->q); } \ No newline at end of file diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index a4f5dd17bf..03fad980b5 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -27,7 +27,6 @@ typedef struct { typedef struct SSvrConn { int32_t ref; uv_tcp_t* pTcp; - queue wreqQueue; uv_timer_t pTimer; queue queue; @@ -1227,7 +1226,6 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); } - transReqQueueInit(&pConn->wreqQueue); QUEUE_INIT(&pConn->queue); if ((code = transQueueInit(&pConn->resps, uvDestroyResp)) != 0) { @@ -1359,7 +1357,6 @@ static void uvDestroyConn(uv_handle_t* handle) { tDebug("%s conn %p destroy", transLabel(pInst), conn); transQueueDestroy(&conn->resps); - transReqQueueClear(&conn->wreqQueue); QUEUE_REMOVE(&conn->queue); From 7acf61f02b6571729260c7d1afdf4fd034532acf Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 14 Sep 2024 18:06:25 +0800 Subject: [PATCH 086/240] opt parameter --- source/libs/transport/inc/transComm.h | 2 +- source/libs/transport/src/transCli.c | 18 ++++++++++-------- source/libs/transport/src/transSvr.c | 1 - 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 4bf62f2067..b931118f04 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -494,7 +494,7 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pWhiteList, char** ppBuf); enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; -#define BUFFER_LIMIT 8 +#define BUFFER_LIMIT 4 typedef struct { queue q; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f8328c5b69..7c2e3e507f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -493,9 +493,10 @@ int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, ST if (pCtx == 0) { return TSDB_CODE_RPC_NO_STATE; } + STraceId* trace = &pHead->traceId; pResp->info.ahandle = transCtxDumpVal(pCtx, pHead->msgType); - tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(conn), conn, pResp->info.ahandle, - TMSG_INFO(pHead->msgType)); + tGDebug("%s conn %p %s received from %s, local info:%s, qid:%ld, create ahandle %p by %s", CONN_GET_INST_LABEL(conn), + conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, qId, pResp->info.ahandle, TMSG_INFO(pHead->msgType)); return 0; } @@ -762,7 +763,6 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->list->size += 1; tDebug("conn %p added to pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); - conn->heap = NULL; conn->seq = 0; if (conn->list->size >= 10) { @@ -3125,7 +3125,7 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentNum, int32_t stateNum) { int32_t total = reqNum + sentNum + stateNum; - if (total >= 4) { + if (total >= BUFFER_LIMIT) { return 1; } @@ -3165,6 +3165,8 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { if (pConn->heap != NULL) { p = pConn->heap; + tDebug("conn %p add to heap cache for key:%s,status:%d, refCnt:%d, add direct", pConn, pConn->dstAddr, + pConn->inHeap, pConn->reqRefCnt); } else { code = getOrCreateHeap(pConnHeapCacahe, pConn->dstAddr, &p); if (code != 0) { @@ -3173,13 +3175,14 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { } code = transHeapInsert(p, pConn); - tDebug("add conn %p to heap cache for key:%s,status:%d, refCnt:%d", pConn, pConn->dstAddr, pConn->inHeap, + tDebug("conn %p add to heap cache for key:%s,status:%d, refCnt:%d", pConn, pConn->dstAddr, pConn->inHeap, pConn->reqRefCnt); return code; } static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { if (pConn->heap != NULL) { + tDebug("conn %p delete from heap cache direct", pConn); return transHeapDelete(pConn->heap, pConn); } @@ -3190,7 +3193,7 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { } int32_t code = transHeapDelete(p, pConn); if (code != 0) { - tDebug("failed to delete conn %p from heap cache since %s", pConn, tstrerror(code)); + tDebug("%s conn failed to delete conn %p from heap cache since %s", pConn, tstrerror(code)); } return code; } @@ -3253,8 +3256,7 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { p->reqRefCnt--; if (p->reqRefCnt == 0) { heapRemove(heap->heap, &p->node); - p->heap = NULL; - tDebug("delete conn %p delete from heap", p); + tDebug("conn %p delete from heap", p); } else if (p->reqRefCnt < 0) { tDebug("conn %p has %d reqs, not delete from heap,assert", p, p->reqRefCnt); } else { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 03fad980b5..c5fc6067e8 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -779,7 +779,6 @@ static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* buf } if (count == 0) { - taosMemoryFree(pWb); return 0; } From 860ca7963f52b999bc5e016257f91ba374629313 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 14 Sep 2024 18:37:37 +0800 Subject: [PATCH 087/240] opt parameter --- source/libs/transport/inc/transComm.h | 3 ++- source/libs/transport/src/transComm.c | 11 +++++++++-- source/libs/transport/src/transSvr.c | 19 ++++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index b931118f04..376c764f2c 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -497,7 +497,8 @@ enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; #define BUFFER_LIMIT 4 typedef struct { - queue q; + queue node; // queue for write + queue q; // queue for reqs uv_write_t wreq; void* arg; } SWReqsWrapper; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 7814ccafac..8f3a112058 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -15,7 +15,7 @@ #include "transComm.h" -#define BUFFER_CAP 16 * 4096 +#define BUFFER_CAP 8 * 1024 static TdThreadOnce transModuleInit = PTHREAD_ONCE_INIT; @@ -893,6 +893,7 @@ int32_t initWQ(queue* wq) { SWReqsWrapper* w = taosMemoryCalloc(1, sizeof(SWReqsWrapper)); w->wreq.data = w; w->arg = NULL; + QUEUE_INIT(&w->node); QUEUE_PUSH(wq, &w->q); } return 0; @@ -912,13 +913,19 @@ uv_write_t* allocWReqFromWQ(queue* wq, void* arg) { QUEUE_REMOVE(node); SWReqsWrapper* w = QUEUE_DATA(node, SWReqsWrapper, q); w->arg = arg; + QUEUE_INIT(&w->node); + return &w->wreq; } else { SWReqsWrapper* w = taosMemoryCalloc(1, sizeof(SWReqsWrapper)); w->wreq.data = w; w->arg = arg; + QUEUE_INIT(&w->node); return &w->wreq; } } -void freeWReqToWQ(queue* wq, SWReqsWrapper* w) { QUEUE_PUSH(wq, &w->q); } \ No newline at end of file +void freeWReqToWQ(queue* wq, SWReqsWrapper* w) { + QUEUE_INIT(&w->node); + QUEUE_PUSH(wq, &w->q); +} \ No newline at end of file diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index c5fc6067e8..20e3df98ec 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -648,16 +648,17 @@ void uvOnSendCb(uv_write_t* req, int status) { STUB_RAND_NETWORK_ERR(status); SWReqsWrapper* wrapper = req->data; + SSvrConn* conn = wrapper->arg; - SWriteReq* userReq = wrapper->arg; - SSvrConn* conn = userReq->conn; - queue* src = &userReq->node; + queue src; + QUEUE_INIT(&src); + QUEUE_MOVE(&wrapper->node, &src); freeWReqToWQ(&conn->wq, wrapper); tDebug("%s conn %p send data out ", transLabel(conn->pInst), conn); if (status == 0) { - while (!QUEUE_IS_EMPTY(src)) { + while (!QUEUE_IS_EMPTY(&src)) { queue* head = QUEUE_HEAD(&src); QUEUE_REMOVE(head); @@ -668,7 +669,7 @@ void uvOnSendCb(uv_write_t* req, int status) { destroySmsg(smsg); } } else { - while (!QUEUE_IS_EMPTY(src)) { + while (!QUEUE_IS_EMPTY(&src)) { queue* head = QUEUE_HEAD(&src); QUEUE_REMOVE(head); @@ -682,7 +683,6 @@ void uvOnSendCb(uv_write_t* req, int status) { conn->broken = true; transUnrefSrvHandle(conn); } - taosMemoryFree(userReq); transUnrefSrvHandle(conn); } static void uvOnPipeWriteCb(uv_write_t* req, int status) { @@ -800,11 +800,8 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { return; } - SWriteReq* pWreq = taosMemoryCalloc(1, sizeof(SWriteReq)); - pWreq->conn = pConn; - QUEUE_INIT(&pWreq->node); - - uv_write_t* req = allocWReqFromWQ(&pConn->wq, pWreq); + uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); + SWReqsWrapper* pWreq = req->data; uv_buf_t* pBuf = NULL; int32_t bufNum = 0; From 9ac3ca9b2f05833542d14b80a75dfd807c23eb15 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 15 Sep 2024 08:15:08 +0800 Subject: [PATCH 088/240] Merge branch '3.0' into enh/opt-transport --- include/os/osSocket.h | 4 +++- source/os/src/osSocket.c | 45 ++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 48478c8f49..0704ff7b0c 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -138,6 +138,7 @@ int32_t taosShutDownSocketRDWR(TdSocketPtr pSocket); int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer); int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on); int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t optlen); +int32_t taosSetSockOpt2(int32_t fd); int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t *optlen); int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); @@ -160,7 +161,7 @@ TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, st int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen); int32_t taosBlockSIGPIPE(); -int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip); +int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip); int32_t taosGetFqdn(char *); void tinet_ntoa(char *ipstr, uint32_t ip); uint32_t ip2uint(const char *const ip_addr); @@ -171,6 +172,7 @@ const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len); uint64_t taosHton64(uint64_t val); uint64_t taosNtoh64(uint64_t val); +int32_t taosSetSockOpt2(int32_t fd); #ifdef __cplusplus } #endif diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 851615fb7f..0dbdf5094d 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -55,7 +55,7 @@ typedef struct TdSocket { #endif int refId; SocketFd fd; -} *TdSocketPtr, TdSocket; +} * TdSocketPtr, TdSocket; typedef struct TdSocketServer { #if SOCKET_WITH_LOCK @@ -63,7 +63,7 @@ typedef struct TdSocketServer { #endif int refId; SocketFd fd; -} *TdSocketServerPtr, TdSocketServer; +} * TdSocketServerPtr, TdSocketServer; typedef struct TdEpoll { #if SOCKET_WITH_LOCK @@ -71,7 +71,7 @@ typedef struct TdEpoll { #endif int refId; EpollFd fd; -} *TdEpollPtr, TdEpoll; +} * TdEpollPtr, TdEpoll; #if 0 int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags, const struct sockaddr *dest_addr, @@ -145,7 +145,7 @@ int32_t taosCloseSocket(TdSocketPtr *ppSocket) { code = taosCloseSocketNoCheck1((*ppSocket)->fd); (*ppSocket)->fd = -1; taosMemoryFree(*ppSocket); - + return code; } @@ -274,7 +274,7 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void terrno = TSDB_CODE_INVALID_PARA; return terrno; } - + #ifdef WINDOWS #ifdef TCP_KEEPCNT if (level == SOL_SOCKET && optname == TCP_KEEPCNT) { @@ -339,7 +339,7 @@ uint32_t taosInetAddr(const char *ipAddr) { #endif } const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len) { - const char* r = inet_ntop(AF_INET, &ipInt, dstStr, len); + const char *r = inet_ntop(AF_INET, &ipInt, dstStr, len); if (NULL == r) { terrno = TAOS_SYSTEM_ERROR(errno); } @@ -787,16 +787,16 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) { TAOS_SKIP_ERROR(taosCloseSocket(&pSocket)); return false; } - + /* bind socket to server address */ if (-1 == bind(pSocket->fd, (struct sockaddr *)&serverAdd, sizeof(serverAdd))) { terrno = TAOS_SYSTEM_ERROR(errno); TAOS_SKIP_ERROR(taosCloseSocket(&pSocket)); return false; } - + TAOS_SKIP_ERROR(taosCloseSocket(&pSocket)); - + return true; } @@ -1039,7 +1039,7 @@ int32_t taosGetFqdn(char *fqdn) { // hints.ai_family = AF_INET; strcpy(fqdn, hostname); strcpy(fqdn + strlen(hostname), ".local"); -#else // linux +#else // linux #endif // linux @@ -1058,7 +1058,7 @@ int32_t taosGetFqdn(char *fqdn) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - + terrno = TAOS_SYSTEM_ERROR(ret); return terrno; } @@ -1092,14 +1092,14 @@ void tinet_ntoa(char *ipstr, uint32_t ip) { (void)sprintf(ipstr, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24); } -int32_t taosIgnSIGPIPE() { - sighandler_t h = signal(SIGPIPE, SIG_IGN); +int32_t taosIgnSIGPIPE() { + sighandler_t h = signal(SIGPIPE, SIG_IGN); if (SIG_ERR == h) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - return 0; + return 0; } #if 0 @@ -1142,7 +1142,7 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } - + #if defined(WINDOWS) if (0 != setsockopt(fd, IPPROTO_TCP, TCP_MAXRT, (char *)&timeout, sizeof(timeout))) { taosCloseSocketNoCheck1(fd); @@ -1212,3 +1212,18 @@ uint64_t taosNtoh64(uint64_t val) { } #endif } + +int32_t taosSetSockOpt2(int32_t fd) { +#if defined(WINDOWS) || defined(DARWIN) + return 0; +#else + int32_t ret = setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } else { + return 0; + } +#endif + return 0; +} From 3ea509d3c7084a970ef6b85db2c1d4ded878f693 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 15 Sep 2024 15:44:03 +0800 Subject: [PATCH 089/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 12 ++++++------ source/libs/transport/src/transSvr.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index bb140efeeb..826b572018 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -361,7 +361,7 @@ void cliResetConnTimer(SCliConn* conn) { } } -void cliHandleBatchResp(SCliConn* conn) { ASSERT(0); } +void cliHandleBatchResp(SCliConn* conn) { return; } void destroyCliConnQTable(SCliConn* conn) { void* pIter = taosHashIterate(conn->pQTable, NULL); @@ -523,7 +523,7 @@ void cliHandleResp(SCliConn* conn) { taosMemoryFree(pHead); tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb - ASSERT(0); + // ASSERT(0); pThrd->notifyExceptCb(pThrd, NULL, NULL); return; } @@ -831,8 +831,8 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { return; } int32_t fd; - uv_fileno((uv_handle_t*)handle, &fd); - taosSetSockOpt2(fd); + (void)uv_fileno((uv_handle_t*)handle, &fd); + (void)taosSetSockOpt2(fd); SCliConn* conn = handle->data; @@ -1635,8 +1635,8 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { // do nothing, notiy return; } else { - ASSERT(code == 0); - addConnToHeapCache(pThrd->connHeapCache, pConn); + /// ASSERT(code == 0); + (void)addConnToHeapCache(pThrd->connHeapCache, pConn); } } code = cliHandleState_mayUpdateState(pThrd, pReq, pConn); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 71ef2cd527..df97061a88 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -551,13 +551,13 @@ static bool uvHandleReq(SSvrConn* pConn) { } if (pHead->seqNum == 0) { - ASSERT(0); + // ASSERT(0); } transMsg.info.handle = (void*)transAcquireExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId); transMsg.info.refIdMgt = pThrd->connRefMgt; - ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg"); + // ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg"); // pHead->noResp = 1, // 1. server application should not send resp on handle @@ -601,9 +601,8 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { } STrans* pInst = conn->pInst; int32_t fd = 0; - uv_fileno((uv_handle_t*)cli, &fd); - taosSetSockOpt2(fd); - setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){1}, sizeof(int)); + (void)uv_fileno((uv_handle_t*)cli, &fd); + (void)taosSetSockOpt2(fd); SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { @@ -727,10 +726,11 @@ static int uvPrepareSendData(SSvrRespMsg* 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) { - ASSERT(0); - // (void)transQueuePop(&pConn->resps); - // destroySmsg(smsg); - // return TSDB_CODE_INVALID_MSG; + // ASSERT(0); + // (void)transQueuePop(&pConn->resps); + // destroySmsg(smsg); + // return TSDB_CODE_INVALID_MSG; + return 0; } pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); @@ -1626,7 +1626,7 @@ void uvHandleQuit(SSvrRespMsg* msg, SWorkThrd* thrd) { taosMemoryFree(msg); } void uvHandleRelease(SSvrRespMsg* msg, SWorkThrd* thrd) { - ASSERT(0); + return; // int32_t code = 0; // SSvrConn* conn = msg->pConn; // if (conn->status == ConnAcquire) { From 832358bd5e583c909d5d8db67c1ea627ddb89007 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 15 Sep 2024 16:40:31 +0800 Subject: [PATCH 090/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 45 +++++++++++--------- source/libs/transport/src/transComm.c | 4 +- source/libs/transport/src/transSvr.c | 59 ++++++++++++++------------- 3 files changed, 57 insertions(+), 51 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 826b572018..b740968007 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -445,8 +445,9 @@ int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead int64_t qId = taosHton64(pHead->qid); STraceId* trace = &pHead->traceId; int32_t seqNum = htonl(pHead->seqNum); - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seqNum:%d, qid:%ld", CONN_GET_INST_LABEL(conn), - conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, seqNum, qId); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seqNum:%d, qid:%" PRId64 "", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, seqNum, + qId); STransCtx* p = taosHashGet(conn->pQTable, &qId, sizeof(qId)); transCtxCleanup(p); @@ -469,6 +470,9 @@ int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead transQueueRemoveByFilter(&conn->reqsSentOut, filterByQid, &qId, &set, -1); transQueueRemoveByFilter(&conn->reqsToSend, filterByQid, &qId, &set, -1); + transReleaseExHandle(transGetRefMgt(), qId); + transRemoveExHandle(transGetRefMgt(), qId); + while (!QUEUE_IS_EMPTY(&set)) { queue* el = QUEUE_HEAD(&set); QUEUE_REMOVE(el); @@ -496,8 +500,9 @@ int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, ST } STraceId* trace = &pHead->traceId; pResp->info.ahandle = transCtxDumpVal(pCtx, pHead->msgType); - tGDebug("%s conn %p %s received from %s, local info:%s, qid:%ld, create ahandle %p by %s", CONN_GET_INST_LABEL(conn), - conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, qId, pResp->info.ahandle, TMSG_INFO(pHead->msgType)); + tGDebug("%s conn %p %s received from %s, local info:%s, qid:%" PRId64 ", create ahandle %p by %s", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, qId, pResp->info.ahandle, + TMSG_INFO(pHead->msgType)); return 0; } @@ -553,8 +558,8 @@ void cliHandleResp(SCliConn* conn) { code = cliNotifyCb(conn, NULL, &resp); return; } else { - tDebug("%s conn %p recv unexpected packet, seqNum:%d,qId:%ld reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, - qId, tstrerror(code)); + tDebug("%s conn %p recv unexpected packet, seqNum:%d,qid:%" PRId64 " reason:%s", CONN_GET_INST_LABEL(conn), conn, + seq, qId, tstrerror(code)); } if (code != 0) { tDebug("%s conn %p recv unexpected packet, seqNum:%d, qId:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, @@ -572,8 +577,8 @@ void cliHandleResp(SCliConn* conn) { if (code != 0) { tGDebug("%s conn %p recv invalid packet, seq %d not found", CONN_GET_INST_LABEL(conn), conn, seq); } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%d, qid:%ld", CONN_GET_INST_LABEL(conn), conn, - TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%d, qid:%" PRId64 "", CONN_GET_INST_LABEL(conn), + conn, TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); } code = cliNotifyCb(conn, pReq, &resp); @@ -1207,7 +1212,7 @@ int32_t cliBatchSend(SCliConn* pConn) { pCliMsg->seq = pConn->seq; STraceId* trace = &pCliMsg->msg.info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d, qid:%ld", CONN_GET_INST_LABEL(pConn), pConn, + tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d, qid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); } @@ -1548,17 +1553,17 @@ int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq) { SReqCtx* pCtx = pReq->ctx; SCliThrd* pThrd = pConn->hostThrd; if (pCtx == NULL) { - tDebug("%s conn %p not need to update statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p not need to update statue ctx, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); return 0; } STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (pUserCtx == NULL) { code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &pCtx->userCtx, sizeof(pCtx->userCtx)); - tDebug("%s conn %p succ to add statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to add statue ctx, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } else { transCtxMerge(pUserCtx, &pCtx->userCtx); - tDebug("%s conn %s succ to update statue ctx, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to update statue ctx, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } return 0; } @@ -1575,11 +1580,11 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { if (pReq->ctx == NULL) { return TSDB_CODE_RPC_STATE_DROPED; } - tDebug("%s conn %p failed to get statue, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p failed to get statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { *pConn = pState->conn; - tDebug("%s conn %p succ to get conn of statue, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to get conn of statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } return 0; } @@ -1594,9 +1599,9 @@ int32_t cliHandleState_mayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* SReqState state = {.conn = pConn, .arg = NULL}; code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); if (code != 0) { - tDebug("%s conn %p failed to statue, qid:%ld", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p failed to statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } else { - tDebug("%s conn %p succ to add statue, qid:%ld (1)", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to add statue, qid:%" PRId64 " (1)", transLabel(pThrd->pInst), pConn, qid); } (void)cliHandleState_mayUpdateStateCtx(pConn, pReq); @@ -1615,7 +1620,7 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { (void)cliHandleState_mayUpdateStateCtx(pConn, pReq); } else if (code == TSDB_CODE_RPC_STATE_DROPED) { STraceId* trace = &pReq->msg.info.traceId; - tWarn("%s failed to get statue, qid:%ld", pInst->label, pReq->msg.info.qId); + tWarn("%s failed to get statue, qid:%" PRId64 "", pInst->label, pReq->msg.info.qId); destroyReq(pReq); return; } @@ -2603,7 +2608,7 @@ static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t if (exh == NULL) { return NULL; } else { - tDebug("%s conn %p got", trans->label, exh->handle); + tDebug("onn %p got", exh->handle); } taosWLockLatch(&exh->latch); if (exh->pThrd == NULL && trans != NULL) { @@ -3066,7 +3071,7 @@ int32_t transAllocHandle(int64_t* refId) { QUEUE_INIT(&exh->q); taosInitRWLatch(&exh->latch); - tDebug("trans alloc qid:%ld", exh->refId); + tDebug("trans alloc qid:%" PRId64 ", malloc:%p", exh->refId, exh); *refId = exh->refId; return 0; } @@ -3098,7 +3103,7 @@ int32_t transFreeConnById(void* pInstRef, int64_t transpointId) { pCli->msg = msg; STraceId* trace = &pCli->msg.info.traceId; - tGDebug("%s start to free conn qid:%ld", pInst->label, transpointId); + tGDebug("%s start to free conn qid:%" PRId64 "", pInst->label, transpointId); code = transAsyncSend(pThrd->asyncPool, &pCli->q); if (code != 0) { diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index a02f26d4c6..929f645e7e 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -779,9 +779,7 @@ void transDestroyExHandle(void* handle) { return; } SExHandle* eh = handle; - if (!QUEUE_IS_EMPTY(&eh->q)) { - tDebug("handle %p mem leak", handle); - } + tDebug("trans destroy qid:%" PRId64 ", memory %p", eh->refId, handle); taosMemoryFree(handle); } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index df97061a88..1e9162de9a 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -106,6 +106,8 @@ typedef struct SWorkThrd { int8_t enableIpWhiteList; int32_t connRefMgt; + + int8_t inited; } SWorkThrd; typedef struct SServerObj { @@ -391,24 +393,27 @@ static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* if (pConn->status == ConnNormal && pHead->noResp == 0) { if (cost >= EXCEPTION_LIMIT_US) { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception, seqNum:%d, qid:%ld", + tGDebug( + "%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception, seqNum:%d, qid:%" PRId64 + "", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); + } else { + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, seqNum:%d, qid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); - } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, seqNum:%d, qid:%ld", transLabel(pInst), - pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost, - pTransMsg->info.seqNum, pTransMsg->info.qId); } } else { if (cost >= EXCEPTION_LIMIT_US) { tGDebug( "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception, " - "seqNum:%d, qid:%ld", + "seqNum:%d, qid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); } else { tGDebug( - "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, seqNum:%d, qid:%ld", + "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, seqNum:%d, " + "qid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); } @@ -438,14 +443,14 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); if (p == NULL) { code = TSDB_CODE_RPC_NO_STATE; - tTrace("conn %p recv release, and releady release by server qid:%ld", pConn, qId); + tTrace("conn %p recv release, and releady release by server qid:%" PRId64 "", pConn, qId); } else { SSvrRegArg* arg = p; (pInst->cfp)(pInst->parent, &(arg->msg), NULL); - tTrace("conn %p recv release, notify server app, qid:%ld", pConn, qId); + tTrace("conn %p recv release, notify server app, qid:%" PRId64 "", pConn, qId); (void)taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); - tTrace("conn %p clear state,qid:%ld", pConn, qId); + tTrace("conn %p clear state,qid:%" PRId64 "", pConn, qId); } STransMsg tmsg = {.code = code, @@ -572,8 +577,6 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.info.qId = taosHton64(pHead->qid); transMsg.info.msgType = pHead->msgType; - // uvMaySetConnAcquired(pConn, pHead); - uvPerfLog_receive(pConn, pHead, &transMsg); // set up conn info @@ -668,7 +671,7 @@ void uvOnSendCb(uv_write_t* req, int status) { SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); STraceId* trace = &smsg->msg.info.traceId; - tGDebug("%s conn %p msg already send out, seqNum:%d, qid:%ld", transLabel(conn->pInst), conn, + tGDebug("%s conn %p msg already send out, seqNum:%d, qid:%" PRId64 "", transLabel(conn->pInst), conn, smsg->msg.info.seqNum, smsg->msg.info.qId); destroySmsg(smsg); } @@ -679,7 +682,7 @@ void uvOnSendCb(uv_write_t* req, int status) { SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); STraceId* trace = &smsg->msg.info.traceId; - tGDebug("%s conn %p failed to send, seqNum:%d, qid:%ld, reason:%s", transLabel(conn->pInst), conn, + tGDebug("%s conn %p failed to send, seqNum:%d, qid:%" PRId64 ", reason:%s", transLabel(conn->pInst), conn, smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); destroySmsg(smsg); } @@ -750,7 +753,7 @@ static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { } STraceId* trace = &pMsg->info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d, seqNum:%d, qid:%ld", transLabel(pInst), pConn, + tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d, seqNum:%d, qid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, len, pMsg->info.seqNum, pMsg->info.qId); wb->base = (char*)pHead; @@ -840,7 +843,7 @@ int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE && qid > 0) { SSvrRegArg* p = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (p == NULL) { - tError("%s conn %p already release qid:%ld", transLabel(pConn->pInst), pConn, qid); + tError("%s conn %p already release qid:%" PRId64 "", transLabel(pConn->pInst), pConn, qid); return TSDB_CODE_RPC_NO_STATE; } else { transFreeMsg(p->msg.pCont); @@ -1024,7 +1027,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { // TODO(log other failure reason) tWarn("failed to create connect:%p, reason: %s", q, uv_err_name(nread)); taosMemoryFree(buf->base); - // uv_close((uv_handle_t*)q, NULL); + uv_close((uv_handle_t*)q, NULL); return; } // free memory allocated by @@ -1338,7 +1341,7 @@ void uvConnDestroyAllState(SSvrConn* p) { SSvrRegArg* arg = pIter; int64_t* qid = taosHashGetKey(pIter, NULL); (pInst->cfp)(pInst->parent, &(arg->msg), NULL); - tTrace("conn %p broken, notify server app, qid%ld", p, *qid); + tTrace("conn %p broken, notify server app, qid:%" PRId64 "", p, *qid); pIter = taosHashIterate(pQTable, pIter); } @@ -1524,7 +1527,6 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, code = TSDB_CODE_OUT_OF_MEMORY; goto End; } - srv->pThreadObj[i] = thrd; thrd->pInst = pInit; thrd->quit = false; @@ -1571,7 +1573,9 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, thrd->pipe = &(srv->pipe[i][1]); // init read thrd->fd = fds[0]; + srv->pThreadObj[i] = thrd; + thrd->inited = 1; if ((code = addHandleToWorkloop(thrd, pipeName)) != 0) { goto End; } @@ -1715,6 +1719,7 @@ void destroyWorkThrdObj(SWorkThrd* pThrd) { } transAsyncPoolDestroy(pThrd->asyncPool); uvWhiteListDestroy(pThrd->pWhiteList); + taosCloseRef(pThrd->connRefMgt); taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd); } @@ -1722,15 +1727,13 @@ void destroyWorkThrd(SWorkThrd* pThrd) { if (pThrd == NULL) { return; } - (void)taosThreadJoin(pThrd->thread, NULL); - SRV_RELEASE_UV(pThrd->loop); - TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrRespMsg, destroySmsgWrapper, NULL); - transAsyncPoolDestroy(pThrd->asyncPool); - - uvWhiteListDestroy(pThrd->pWhiteList); - - taosMemoryFree(pThrd->loop); - taosMemoryFree(pThrd); + if (pThrd->inited) { + sendQuitToWorkThrd(pThrd); + (void)taosThreadJoin(pThrd->thread, NULL); + SRV_RELEASE_UV(pThrd->loop); + TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrRespMsg, destroySmsgWrapper, NULL); + } + destroyWorkThrdObj(pThrd); } void sendQuitToWorkThrd(SWorkThrd* pThrd) { SSvrRespMsg* msg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); From e9d84f81318ba529260fb720e84053dc36ca8cfb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 08:22:49 +0800 Subject: [PATCH 091/240] Merge branch '3.0' into enh/opt-transport --- source/libs/scheduler/src/schRemote.c | 4 +++ source/libs/transport/src/transCli.c | 37 ++++++++++++--------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 40391cea7e..bb06a25ce0 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -501,6 +501,10 @@ int32_t schHandleDropCallback(void *param, SDataBuf *pMsg, int32_t code) { code); // called if drop task rsp received code (void)rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT); // ignore error + + if (pMsg->handle == NULL) { + ASSERT(0); + } if (pMsg) { taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b740968007..c9a23d76be 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -216,7 +216,7 @@ SCliBatch* cliGetHeadFromList(SCliBatchList* pList); static void destroyCliConnQTable(SCliConn* conn); -static void cliHandleBatch_shareConnExcept(SCliConn* conn); +static void cliHandleException(SCliConn* conn); static int32_t allocConnRef(SCliConn* conn, bool update); static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); @@ -976,7 +976,7 @@ _failed: taosMemoryFree(conn); return code; } -static void cliDestroyConn(SCliConn* conn, bool clear) { cliHandleBatch_shareConnExcept(conn); } +static void cliDestroyConn(SCliConn* conn, bool clear) { cliHandleException(conn); } static void cliDestroy(uv_handle_t* handle) { if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) { return; @@ -1021,7 +1021,7 @@ static void cliDestroy(uv_handle_t* handle) { bool filterAllReq(void* e, void* arg) { return 1; } -static void cliHandleBatch_shareConnExcept(SCliConn* conn) { +static void cliHandleException(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; @@ -1046,6 +1046,7 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; resp.info.cliVer = pInst->compatibilityVer; resp.info.ahandle = pCtx ? pCtx->ahandle : 0; + resp.info.handle = pReq->msg.info.handle; if (pReq) { resp.info.traceId = pReq->msg.info.traceId; } @@ -1065,9 +1066,11 @@ static void cliHandleBatch_shareConnExcept(SCliConn* conn) { destroyReq(pReq); } } - int8_t ref = transGetRefCount(conn); - if (ref == 0 && !uv_is_closing((uv_handle_t*)conn->stream)) { - uv_close((uv_handle_t*)conn->stream, cliDestroy); + if (conn->registered) { + int8_t ref = transGetRefCount(conn); + if (ref == 0 && !uv_is_closing((uv_handle_t*)conn->stream)) { + uv_close((uv_handle_t*)conn->stream, cliDestroy); + } } } @@ -1296,19 +1299,13 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { return TSDB_CODE_RPC_ASYNC_IN_PROCESS; _exception1: - tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, uv_err_name(code)); - // taosMemoryFree(conn); // free conn later + tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, tstrerror(code)); + cliDestroyConn(conn, true); return code; _exception2: - // already registered to uv, callback handle error - tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, uv_err_name(code)); - // cliRmReqFromConn(conn, NULL); - - // cliResetConnTimer(conn); - // cliMayUpdateFqdnCache(pThrd->fqdn2ipCache, conn->dstAddr); - - // // taosMemoryFree(conn); + transUnrefCliHandle(conn); + tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, tstrerror(code)); return code; } @@ -1639,9 +1636,11 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { } else if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { // do nothing, notiy return; - } else { - /// ASSERT(code == 0); + } else if (code == 0) { (void)addConnToHeapCache(pThrd->connHeapCache, pConn); + } else { + // do nothing, notiy + return; } } code = cliHandleState_mayUpdateState(pThrd, pReq, pConn); @@ -2607,8 +2606,6 @@ static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle); if (exh == NULL) { return NULL; - } else { - tDebug("onn %p got", exh->handle); } taosWLockLatch(&exh->latch); if (exh->pThrd == NULL && trans != NULL) { From b5c1b672a4d6dd2405cc37025d806f08e47ddbdd Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 09:29:43 +0800 Subject: [PATCH 092/240] Merge branch '3.0' into enh/opt-transport --- include/libs/transport/trpc.h | 2 +- source/libs/transport/inc/transComm.h | 2 +- source/libs/transport/src/transCli.c | 78 ++++++--------------------- source/libs/transport/src/transSvr.c | 33 ++++++------ 4 files changed, 34 insertions(+), 81 deletions(-) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 72e66e268f..d9712dde4a 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -63,7 +63,7 @@ typedef struct SRpcHandleInfo { int8_t forbiddenIp; int8_t notFreeAhandle; int8_t compressed; - int32_t seqNum; // msg seq + int64_t seqNum; // msg seq int64_t qId; // queryId Get from client, other req's qId = -1; int32_t refIdMgt; int32_t msgType; diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 985ec1cb6a..7964a9479d 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -185,7 +185,7 @@ typedef struct { uint32_t code; // del later uint32_t msgType; int32_t msgLen; - int32_t seqNum; + int64_t seqNum; uint8_t content[0]; // message body starts from here } STransMsgHead; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c9a23d76be..c2ce95b651 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -92,7 +92,7 @@ typedef struct SCliConn { int32_t port; int64_t refId; - int32_t seq; + int64_t seq; int8_t registered; int8_t connnected; @@ -127,7 +127,7 @@ typedef struct SCliReq { uint64_t st; int sent; //(0: no send, 1: alread sent) queue seqq; - int32_t seq; + int64_t seq; queue qlist; } SCliReq; @@ -375,7 +375,7 @@ void destroyCliConnQTable(SCliConn* conn) { conn->pQTable = NULL; } bool filteBySeq(void* key, void* arg) { - int32_t* seq = arg; + int64_t* seq = arg; SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); if (pReq->seq == *seq) { return true; @@ -383,7 +383,7 @@ bool filteBySeq(void* key, void* arg) { return false; } } -int32_t cliGetReqBySeq(SCliConn* conn, int32_t seq, SCliReq** pReq) { +int32_t cliGetReqBySeq(SCliConn* conn, int64_t seq, SCliReq** pReq) { int32_t code = 0; queue set; QUEUE_INIT(&set) @@ -432,7 +432,7 @@ int32_t cliBuildRespFromCont(SCliReq* pReq, STransMsg* pResp, STransMsgHead* pHe pResp->info.traceId = pHead->traceId; pResp->info.hasEpSet = pHead->hasEpSet; pResp->info.cliVer = htonl(pHead->compatibilityVer); - pResp->info.seqNum = htonl(pHead->seqNum); + pResp->info.seqNum = taosHton64(pHead->seqNum); int64_t qid = taosHton64(pHead->qid); pResp->info.handle = (void*)qid; @@ -444,8 +444,8 @@ int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead if (pHead->msgType == TDMT_SCH_TASK_RELEASE || pHead->msgType == TDMT_SCH_TASK_RELEASE + 1) { int64_t qId = taosHton64(pHead->qid); STraceId* trace = &pHead->traceId; - int32_t seqNum = htonl(pHead->seqNum); - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seqNum:%d, qid:%" PRId64 "", + int64_t seqNum = taosHton64(pHead->seqNum); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seqNum:%" PRId64 ", qid:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, seqNum, qId); @@ -541,7 +541,7 @@ void cliHandleResp(SCliConn* conn) { int64_t qId = taosHton64(pHead->qid); pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); - int32_t seq = htonl(pHead->seqNum); + int64_t seq = taosHton64(pHead->seqNum); STransMsg resp = {0}; if (cliHandleState_mayHandleReleaseResp(conn, pHead)) { @@ -558,12 +558,13 @@ void cliHandleResp(SCliConn* conn) { code = cliNotifyCb(conn, NULL, &resp); return; } else { - tDebug("%s conn %p recv unexpected packet, seqNum:%d,qid:%" PRId64 " reason:%s", CONN_GET_INST_LABEL(conn), conn, - seq, qId, tstrerror(code)); + tDebug("%s conn %p recv unexpected packet, seqNum:%" PRId64 ",qid:%" PRId64 " reason:%s", + CONN_GET_INST_LABEL(conn), conn, seq, qId, tstrerror(code)); } if (code != 0) { - tDebug("%s conn %p recv unexpected packet, seqNum:%d, qId:%d, reason:%s", CONN_GET_INST_LABEL(conn), conn, seq, - qId, tstrerror(code)); + tDebug("%s conn %p recv unexpected packet, msgType:%s, seqNum:%" PRId64 ", qId:%" PRId64 + ", the sever sends repeated response,reason:%s", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), seq, qId, tstrerror(code)); // TODO: notify cb if (cliMayRecycleConn(conn)) { return; @@ -603,7 +604,7 @@ void cliConnTimeout(uv_timer_t* handle) { return; } - tTrace("%s conn %p conn timeout", CONN_GET_INST_LABEL(conn)); + tTrace("%s conn %p conn timeout", CONN_GET_INST_LABEL(conn), conn); } void* createConnPool(int size) { @@ -631,50 +632,6 @@ void* destroyConnPool(SCliThrd* pThrd) { return NULL; } -// static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) { -// void* pool = pThrd->pool; -// STrans* pTranInst = pThrd->pInst; -// size_t klen = strlen(key); -// SConnList* plist = taosHashGet((SHashObj*)pool, key, klen); -// if (plist == NULL) { -// SConnList list = {0}; -// (void)taosHashPut((SHashObj*)pool, key, klen, (void*)&list, sizeof(list)); -// plist = taosHashGet(pool, key, klen); - -// // SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList)); -// // QUEUE_INIT(&nList->msgQ); -// // nList->numOfConn++; - -// QUEUE_INIT(&plist->conns); -// //plist->list = nList; -// } - -// if (QUEUE_IS_EMPTY(&plist->conns)) { -// if (plist->list->numOfConn >= pTranInst->connLimitNum) { -// *exceed = true; -// return NULL; -// } -// plist->list->numOfConn++; -// return NULL; -// } - -// queue* h = QUEUE_TAIL(&plist->conns); -// QUEUE_REMOVE(h); -// plist->size -= 1; - -// SCliConn* conn = QUEUE_DATA(h, SCliConn, q); -// conn->status = ConnNormal; -// QUEUE_INIT(&conn->q); -// tDebug("conn %p get from pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); - -// if (conn->task != NULL) { -// transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); -// conn->task = NULL; -// } -// conn->seq++; -// return conn; -// } - static int32_t getOrCreateConnList(SCliThrd* pThrd, const char* key, SConnList** ppList) { int32_t code = 0; void* pool = pThrd->pool; @@ -724,7 +681,6 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p SCliConn* conn = QUEUE_DATA(h, SCliConn, q); conn->status = ConnNormal; QUEUE_INIT(&conn->q); - conn->seq = 0; conn->list = plist; if (conn->task != NULL) { @@ -773,8 +729,6 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->list->size += 1; tDebug("conn %p added to pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); - conn->seq = 0; - if (conn->list->size >= 10) { STaskArg* arg = taosMemoryCalloc(1, sizeof(STaskArg)); if (arg == NULL) return; @@ -1197,7 +1151,7 @@ int32_t cliBatchSend(SCliConn* pConn) { pHead->compatibilityVer = htonl(pInst->compatibilityVer); } pHead->timestamp = taosHton64(taosGetTimestampUs()); - pHead->seqNum = htonl(pConn->seq); + pHead->seqNum = taosHton64(pConn->seq); pHead->qid = taosHton64(pReq->info.qId); if (pHead->comp == 0) { @@ -3210,7 +3164,7 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { } int32_t code = transHeapDelete(p, pConn); if (code != 0) { - tDebug("%s conn failed to delete conn %p from heap cache since %s", pConn, tstrerror(code)); + tDebug("conn %p failed delete from heap cache since %s", pConn, tstrerror(code)); } return code; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 1e9162de9a..46bc1bfd2d 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -71,7 +71,7 @@ typedef struct SSvrRespMsg { STransMsg msg; queue q; STransMsgType type; - int32_t seqNum; + int64_t seqNum; void* arg; FilteFunc func; int8_t sent; @@ -393,13 +393,12 @@ static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* if (pConn->status == ConnNormal && pHead->noResp == 0) { if (cost >= EXCEPTION_LIMIT_US) { - tGDebug( - "%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception, seqNum:%d, qid:%" PRId64 - "", - transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, - (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception, seqNum:%" PRId64 + ", qid:%" PRId64 "", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, seqNum:%d, qid:%" PRId64 "", + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, seqNum:%" PRId64 ", qid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); } @@ -407,15 +406,15 @@ static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* if (cost >= EXCEPTION_LIMIT_US) { tGDebug( "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception, " - "seqNum:%d, qid:%" PRId64 "", + "seqNum:%" PRId64 ", qid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); } else { - tGDebug( - "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, seqNum:%d, " - "qid:%" PRId64 "", - transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, - pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, seqNum:%" PRId64 + ", " + "qid:%" PRId64 "", + transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, + pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); } } tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pInst), pTransMsg->info.handle, pConn, @@ -457,7 +456,7 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { .msgType = pHead->msgType + 1, .info.qId = qId, .info.traceId = pHead->traceId, - .info.seqNum = htonl(pHead->seqNum)}; + .info.seqNum = taosHton64(pHead->seqNum)}; SSvrRespMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); srvMsg->msg = tmsg; @@ -573,7 +572,7 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.info.cliVer = htonl(pHead->compatibilityVer); transMsg.info.forbiddenIp = forbiddenIp; transMsg.info.noResp = pHead->noResp == 1 ? 1 : 0; - transMsg.info.seqNum = htonl(pHead->seqNum); + transMsg.info.seqNum = taosHton64(pHead->seqNum); transMsg.info.qId = taosHton64(pHead->qid); transMsg.info.msgType = pHead->msgType; @@ -671,7 +670,7 @@ void uvOnSendCb(uv_write_t* req, int status) { SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); STraceId* trace = &smsg->msg.info.traceId; - tGDebug("%s conn %p msg already send out, seqNum:%d, qid:%" PRId64 "", transLabel(conn->pInst), conn, + tGDebug("%s conn %p msg already send out, seqNum:%" PRId64 ", qid:%" PRId64 "", transLabel(conn->pInst), conn, smsg->msg.info.seqNum, smsg->msg.info.qId); destroySmsg(smsg); } @@ -723,7 +722,7 @@ static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { pHead->magicNum = htonl(TRANS_MAGIC_NUM); pHead->compatibilityVer = htonl(((STrans*)pConn->pInst)->compatibilityVer); pHead->version = TRANS_VER; - pHead->seqNum = htonl(pMsg->info.seqNum); + pHead->seqNum = taosHton64(pMsg->info.seqNum); pHead->qid = taosHton64(pMsg->info.qId); pHead->withUserInfo = pConn->userInited == 0 ? 1 : 0; From 9ecb9b23e78b235c8ed93cff703d0b0ecc1f83a4 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 13:17:39 +0800 Subject: [PATCH 093/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/inc/transComm.h | 4 +- source/libs/transport/src/transCli.c | 104 +++++++++++++++++++++----- source/libs/transport/src/transComm.c | 2 +- 3 files changed, 90 insertions(+), 20 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 7964a9479d..ea79e3582f 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -496,7 +496,9 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pWhiteList, char** ppBuf); enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; -#define BUFFER_LIMIT 4 +#define BUFFER_LIMIT 4 +#define HEAP_MISS_HIT_LIMIT 100000 +#define READ_TIMEOUT 100000 typedef struct { queue node; // queue for write diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c2ce95b651..10df19d3c8 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -100,7 +100,8 @@ typedef struct SCliConn { int8_t userInited; void* pInitUserReq; - void* heap; // point to req conn heap + void* heap; // point to req conn heap + int32_t heapMissHit; uv_buf_t* buf; int32_t bufSize; @@ -198,6 +199,8 @@ static int32_t cliBatchSend(SCliConn* conn); bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead); // register conn timer static void cliConnTimeout(uv_timer_t* handle); + +void cliConnTimeout__checkReq(uv_timer_t* handle); // register timer for read static void cliReadTimeoutCb(uv_timer_t* handle); // register timer in each thread to clear expire conn @@ -361,6 +364,15 @@ void cliResetConnTimer(SCliConn* conn) { } } +void cliConnSetReadTimeout(SCliConn* conn, int timeout) { + if (conn->timer == NULL) { + if (cliGetConnTimer(conn->hostThrd, conn) != 0) { + return; + } + } + uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); +} + void cliHandleBatchResp(SCliConn* conn) { return; } void destroyCliConnQTable(SCliConn* conn) { @@ -517,9 +529,9 @@ void cliHandleResp(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - cliConnClearInitUserMsg(conn); - cliResetConnTimer(conn); + + cliConnClearInitUserMsg(conn); SCliReq* pReq = NULL; STransMsgHead* pHead = NULL; @@ -562,9 +574,9 @@ void cliHandleResp(SCliConn* conn) { CONN_GET_INST_LABEL(conn), conn, seq, qId, tstrerror(code)); } if (code != 0) { - tDebug("%s conn %p recv unexpected packet, msgType:%s, seqNum:%" PRId64 ", qId:%" PRId64 - ", the sever sends repeated response,reason:%s", - CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), seq, qId, tstrerror(code)); + tWarn("%s conn %p recv unexpected packet, msgType:%s, seqNum:%" PRId64 ", qId:%" PRId64 + ", the sever may sends repeated response,reason:%s", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), seq, qId, tstrerror(code)); // TODO: notify cb if (cliMayRecycleConn(conn)) { return; @@ -575,16 +587,11 @@ void cliHandleResp(SCliConn* conn) { code = cliBuildRespFromCont(pReq, &resp, pHead); STraceId* trace = &resp.info.traceId; - if (code != 0) { - tGDebug("%s conn %p recv invalid packet, seq %d not found", CONN_GET_INST_LABEL(conn), conn, seq); - } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%d, qid:%" PRId64 "", CONN_GET_INST_LABEL(conn), - conn, TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); - } + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%d, qid:%" PRId64 "", CONN_GET_INST_LABEL(conn), + conn, TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); code = cliNotifyCb(conn, pReq, &resp); if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { - STraceId* trace = &resp.info.traceId; tGWarn("%s msg need retry", CONN_GET_INST_LABEL(conn)); } else { destroyReq(pReq); @@ -592,6 +599,8 @@ void cliHandleResp(SCliConn* conn) { if (cliMayRecycleConn(conn)) { return; } + if (transQueueSize(&conn->reqsSentOut)) cliConnSetReadTimeout(conn, READ_TIMEOUT); + (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } @@ -607,6 +616,39 @@ void cliConnTimeout(uv_timer_t* handle) { tTrace("%s conn %p conn timeout", CONN_GET_INST_LABEL(conn), conn); } +bool filterToRmTimoutReq(void* key, void* arg) { + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->msg.info.qId == 0 && REQUEST_NO_RESP(&pReq->msg)) { + int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000); + if (elapse > READ_TIMEOUT) { + return true; + } + return true; + } + return false; +} +void cliConnTimeout__checkReq(uv_timer_t* handle) { + queue set; + QUEUE_INIT(&set); + + SCliConn* conn = handle->data; + SCliThrd* pThrd = conn->hostThrd; + if (transQueueSize(&conn->reqsSentOut) == 0) { + return; + } + + transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmTimoutReq, NULL, &set, -1); + + while (!QUEUE_IS_EMPTY(&set)) { + queue* el = QUEUE_HEAD(&set); + QUEUE_REMOVE(el); + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + STraceId* trace = &pReq->msg.info.traceId; + tDebug("%s conn %p req %s timeout, start to free", CONN_GET_INST_LABEL(conn), conn, pReq->msg.msgType); + destroyReqWrapper(pReq, pThrd); + } +} + void* createConnPool(int size) { // thread local, no lock return taosHashInit(size, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); @@ -729,6 +771,8 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->list->size += 1; tDebug("conn %p added to pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); + conn->heapMissHit = 0; + if (conn->list->size >= 10) { STaskArg* arg = taosMemoryCalloc(1, sizeof(STaskArg)); if (arg == NULL) return; @@ -980,6 +1024,7 @@ static void cliHandleException(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; + cliResetConnTimer(conn); queue set; QUEUE_INIT(&set); // TODO @@ -1028,7 +1073,7 @@ static void cliHandleException(SCliConn* conn) { } } -bool fileToRmReq(void* h, void* arg) { +bool filterToRmReq(void* h, void* arg) { queue* el = h; SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); if (pReq->sent == 1 && REQUEST_NO_RESP(&pReq->msg)) { @@ -1040,7 +1085,7 @@ static void cliConnRmReqs(SCliConn* conn) { queue set; QUEUE_INIT(&set); - transQueueRemoveByFilter(&conn->reqsSentOut, fileToRmReq, NULL, &set, -1); + transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmReq, NULL, &set, -1); while (!QUEUE_IS_EMPTY(&set)) { queue* el = QUEUE_HEAD(&set); QUEUE_REMOVE(el); @@ -1070,6 +1115,10 @@ static void cliBatchSendCb(uv_write_t* req, int status) { return; } + cliResetConnTimer(conn); + + if (transQueueSize(&conn->reqsSentOut)) cliConnSetReadTimeout(conn, READ_TIMEOUT); + (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); if (!cliMayRecycleConn(conn)) { @@ -1150,7 +1199,7 @@ int32_t cliBatchSend(SCliConn* pConn) { pHead->version = TRANS_VER; pHead->compatibilityVer = htonl(pInst->compatibilityVer); } - pHead->timestamp = taosHton64(taosGetTimestampUs()); + pHead->timestamp = taosHton64(pCliMsg->st); pHead->seqNum = taosHton64(pConn->seq); pHead->qid = taosHton64(pReq->info.qId); @@ -3084,6 +3133,7 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea if (code != 0) { transHeapDestroy(&heap); tError("failed to put heap to cache for key:%s, reason: %s", key, tstrerror(code)); + return code; } p = taosHashGet(pConnHeapCache, key, klen); if (p == NULL) { @@ -3103,6 +3153,24 @@ static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentN return 0; } +static FORCE_INLINE bool filterToDebug(void* e, void* arg) { + SCliReq* pReq = QUEUE_DATA(e, SCliReq, q); + STraceId* trace = &pReq->msg.info.traceId; + tGWarn("%s is sent to, and no resp from server", pReq->msg.msgType); + return false; +} +static FORCE_INLINE int32_t logConnMissHit(SCliConn* pConn) { + queue set; + QUEUE_INIT(&set); + pConn->heapMissHit++; + tDebug("conn %p has %d reqs, %d sentout and %d status in process, total limit:%d, switch to other conn", pConn, + transQueueSize(&pConn->reqsToSend), transQueueSize(&pConn->reqsSentOut), taosHashGetSize(pConn->pQTable), + BUFFER_LIMIT); + if (transQueueSize(&pConn->reqsSentOut) >= BUFFER_LIMIT) { + transQueueRemoveByFilter(&pConn->reqsSentOut, filterToDebug, NULL, &set, 1); + } + return 0; +} static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int code = 0; SHeap* pHeap = NULL; @@ -3123,11 +3191,11 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int32_t stateNum = taosHashGetSize(pConn->pQTable); if (shouldSWitchToOtherConn(reqsNum, reqsSentOut, stateNum)) { - tDebug("conn %p has %d reqs, %d sentout and %d status in process, switch to other conn", pConn, reqsNum, - reqsSentOut, stateNum); + logConnMissHit(pConn); return NULL; } } + return pConn; } static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 929f645e7e..060ab2edae 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -482,7 +482,7 @@ void transQueueRemoveByFilter(STransQueue* q, bool (*filter)(void* e, void* arg) queue* node = QUEUE_NEXT(&q->node); while (node != &q->node) { queue* next = QUEUE_NEXT(node); - if (filter(node, arg)) { + if (filter && filter(node, arg)) { QUEUE_REMOVE(node); q->size--; QUEUE_PUSH(d, node); From 723e863ec40cfb31ae7b08b72e05f6c5cf3bd0a0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 13:23:10 +0800 Subject: [PATCH 094/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 10df19d3c8..72b9889afa 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -628,11 +628,13 @@ bool filterToRmTimoutReq(void* key, void* arg) { return false; } void cliConnTimeout__checkReq(uv_timer_t* handle) { - queue set; + int32_t code = 0; + queue set; QUEUE_INIT(&set); SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; if (transQueueSize(&conn->reqsSentOut) == 0) { return; } @@ -645,7 +647,26 @@ void cliConnTimeout__checkReq(uv_timer_t* handle) { SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); STraceId* trace = &pReq->msg.info.traceId; tDebug("%s conn %p req %s timeout, start to free", CONN_GET_INST_LABEL(conn), conn, pReq->msg.msgType); - destroyReqWrapper(pReq, pThrd); + + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; + STransMsg resp = {0}; + resp.code = TSDB_CODE_RPC_TIMEOUT; + resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; + resp.info.cliVer = pInst->compatibilityVer; + resp.info.ahandle = pCtx ? pCtx->ahandle : 0; + resp.info.handle = pReq->msg.info.handle; + if (pReq) { + resp.info.traceId = pReq->msg.info.traceId; + } + + pReq->seq = 0; + code = cliNotifyCb(conn, pReq, &resp); + if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + continue; + } else { + // already notify user + destroyReqWrapper(pReq, pThrd); + } } } From bbb3d4cc6188b532448aee9e785119e4f1ec1e74 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 16:31:02 +0800 Subject: [PATCH 095/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 40 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 72b9889afa..dbdaa1a4aa 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -196,6 +196,7 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn); static void cliBatchSendCb(uv_write_t* req, int status); void cliBatchSendImpl(SCliConn* pConn); static int32_t cliBatchSend(SCliConn* conn); +void cliConnCheckTimoutMsg(SCliConn* conn); bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead); // register conn timer static void cliConnTimeout(uv_timer_t* handle); @@ -364,7 +365,23 @@ void cliResetConnTimer(SCliConn* conn) { } } -void cliConnSetReadTimeout(SCliConn* conn, int timeout) { +void cliConnMaySetReadTimeout(SCliConn* conn, int timeout) { + if (conn->timer != NULL) { + // reset previous timer + cliResetConnTimer(conn); + } + int32_t reqsSentNum = transQueueSize(&conn->reqsSentOut); + if (reqsSentNum == 0) { + return; + } + + cliConnCheckTimoutMsg(conn); + + if (conn->timer != NULL) { + // reset previous timer + cliResetConnTimer(conn); + } + if (conn->timer == NULL) { if (cliGetConnTimer(conn->hostThrd, conn) != 0) { return; @@ -529,8 +546,6 @@ void cliHandleResp(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - cliResetConnTimer(conn); - cliConnClearInitUserMsg(conn); SCliReq* pReq = NULL; @@ -599,7 +614,8 @@ void cliHandleResp(SCliConn* conn) { if (cliMayRecycleConn(conn)) { return; } - if (transQueueSize(&conn->reqsSentOut)) cliConnSetReadTimeout(conn, READ_TIMEOUT); + + cliConnMaySetReadTimeout(conn, READ_TIMEOUT); (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } @@ -627,12 +643,11 @@ bool filterToRmTimoutReq(void* key, void* arg) { } return false; } -void cliConnTimeout__checkReq(uv_timer_t* handle) { + +void cliConnCheckTimoutMsg(SCliConn* conn) { int32_t code = 0; queue set; QUEUE_INIT(&set); - - SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; if (transQueueSize(&conn->reqsSentOut) == 0) { @@ -668,6 +683,12 @@ void cliConnTimeout__checkReq(uv_timer_t* handle) { destroyReqWrapper(pReq, pThrd); } } + + return; +} +void cliConnTimeout__checkReq(uv_timer_t* handle) { + SCliConn* conn = handle->data; + cliConnCheckTimoutMsg(conn); } void* createConnPool(int size) { @@ -931,7 +952,6 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int conn->ipStr = taosStrdup(ip); conn->port = port; - QUEUE_INIT(&conn->q); conn->hostThrd = pThrd; conn->status = ConnNormal; conn->broken = false; @@ -1136,9 +1156,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { return; } - cliResetConnTimer(conn); - - if (transQueueSize(&conn->reqsSentOut)) cliConnSetReadTimeout(conn, READ_TIMEOUT); + cliConnMaySetReadTimeout(conn, READ_TIMEOUT); (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); From 1a70cc243a6b4f0e9f94a09a6d5187d10a73e514 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 16:36:51 +0800 Subject: [PATCH 096/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index dbdaa1a4aa..c0141dfa3a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -377,11 +377,6 @@ void cliConnMaySetReadTimeout(SCliConn* conn, int timeout) { cliConnCheckTimoutMsg(conn); - if (conn->timer != NULL) { - // reset previous timer - cliResetConnTimer(conn); - } - if (conn->timer == NULL) { if (cliGetConnTimer(conn->hostThrd, conn) != 0) { return; @@ -634,7 +629,7 @@ void cliConnTimeout(uv_timer_t* handle) { bool filterToRmTimoutReq(void* key, void* arg) { SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); - if (pReq->msg.info.qId == 0 && REQUEST_NO_RESP(&pReq->msg)) { + if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000); if (elapse > READ_TIMEOUT) { return true; From c345383d5a1d4f74ef2af68d0f15a4cf227031eb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 17:30:57 +0800 Subject: [PATCH 097/240] Merge branch '3.0' into enh/opt-transport --- include/libs/transport/trpc.h | 1 + source/dnode/mgmt/node_mgmt/src/dmTransport.c | 10 ++++++---- source/libs/transport/inc/transportInt.h | 1 + source/libs/transport/src/trans.c | 2 ++ source/libs/transport/src/transCli.c | 16 +++++++++------- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index d9712dde4a..5d5dc00ad8 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -131,6 +131,7 @@ typedef struct SRpcInit { int32_t batchSize; int8_t shareConn; // 0: no share, 1. share int8_t notWaitAvaliableConn; // 1: wait to get, 0: no wait + int8_t startReadTimer; void *parent; } SRpcInit; diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 1861144bf0..060fce5808 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -109,7 +109,8 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { int32_t svrVer = 0; (void)taosVersionStrToInt(version, &svrVer); if ((code = taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) != 0) { - dError("Version not compatible, cli ver: %d, svr ver: %d, ip:0x%x", pRpc->info.cliVer, svrVer, pRpc->info.conn.clientIp); + dError("Version not compatible, cli ver: %d, svr ver: %d, ip:0x%x", pRpc->info.cliVer, svrVer, + pRpc->info.conn.clientIp); goto _OVER; } @@ -391,7 +392,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.notWaitAvaliableConn = 0; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); - + rpcInit.startReadTimer = 1; pTrans->clientRpc = rpcOpen(&rpcInit); if (pTrans->clientRpc == NULL) { dError("failed to init dnode rpc client since:%s", tstrerror(terrno)); @@ -434,11 +435,12 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.supportBatch = 1; rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; + rpcInit.startReadTimer = 1; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); pTrans->statusRpc = rpcOpen(&rpcInit); if (pTrans->statusRpc == NULL) { - dError("failed to init dnode rpc status client since %s", tstrerror(terrno)); + dError("failed to init dnode rpc status client since %s", tstrerror(terrno)); return terrno; } @@ -480,7 +482,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) { rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); - + rpcInit.startReadTimer = 1; pTrans->syncRpc = rpcOpen(&rpcInit); if (pTrans->syncRpc == NULL) { dError("failed to init dnode rpc sync client since %s", tstrerror(terrno)); diff --git a/source/libs/transport/inc/transportInt.h b/source/libs/transport/inc/transportInt.h index 8199ee21c9..8e10357f07 100644 --- a/source/libs/transport/inc/transportInt.h +++ b/source/libs/transport/inc/transportInt.h @@ -78,6 +78,7 @@ typedef struct { void* tcphandle; // returned handle from TCP initialization int64_t refId; int8_t shareConn; + int8_t startReadTimer; TdThreadMutex mutex; } SRpcInfo; diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index d7ec89f871..bebbcb68d6 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -42,6 +42,8 @@ void* rpcOpen(const SRpcInit* pInit) { if (pRpc == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } + + pRpc->startReadTimer = pInit->startReadTimer; if (pInit->label) { int len = strlen(pInit->label) > sizeof(pRpc->label) ? sizeof(pRpc->label) : strlen(pInit->label); memcpy(pRpc->label, pInit->label, len); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c0141dfa3a..3e47908a86 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -365,7 +365,12 @@ void cliResetConnTimer(SCliConn* conn) { } } -void cliConnMaySetReadTimeout(SCliConn* conn, int timeout) { +void cliConnMayUpdateTimer(SCliConn* conn, int timeout) { + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + if (pInst->startReadTimer == 0) { + return; + } if (conn->timer != NULL) { // reset previous timer cliResetConnTimer(conn); @@ -374,9 +379,6 @@ void cliConnMaySetReadTimeout(SCliConn* conn, int timeout) { if (reqsSentNum == 0) { return; } - - cliConnCheckTimoutMsg(conn); - if (conn->timer == NULL) { if (cliGetConnTimer(conn->hostThrd, conn) != 0) { return; @@ -610,7 +612,7 @@ void cliHandleResp(SCliConn* conn) { return; } - cliConnMaySetReadTimeout(conn, READ_TIMEOUT); + cliConnMayUpdateTimer(conn, READ_TIMEOUT); (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } @@ -656,7 +658,7 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { QUEUE_REMOVE(el); SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); STraceId* trace = &pReq->msg.info.traceId; - tDebug("%s conn %p req %s timeout, start to free", CONN_GET_INST_LABEL(conn), conn, pReq->msg.msgType); + tDebug("%s conn %p req %s timeout, start to free", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pReq->msg.msgType)); SReqCtx* pCtx = pReq ? pReq->ctx : NULL; STransMsg resp = {0}; @@ -1151,7 +1153,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { return; } - cliConnMaySetReadTimeout(conn, READ_TIMEOUT); + cliConnMayUpdateTimer(conn, READ_TIMEOUT); (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); From 12b560e6db7f7c8698d210d28e7445cc75a5038a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 17:33:03 +0800 Subject: [PATCH 098/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3e47908a86..7e3ca86b6e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -371,18 +371,20 @@ void cliConnMayUpdateTimer(SCliConn* conn, int timeout) { if (pInst->startReadTimer == 0) { return; } + // reset previous timer if (conn->timer != NULL) { // reset previous timer cliResetConnTimer(conn); } int32_t reqsSentNum = transQueueSize(&conn->reqsSentOut); if (reqsSentNum == 0) { + // no need to set timer return; } - if (conn->timer == NULL) { - if (cliGetConnTimer(conn->hostThrd, conn) != 0) { - return; - } + + // start a new timer + if (cliGetConnTimer(conn->hostThrd, conn) != 0) { + return; } uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); } From cf23956f4f2fbaba626c85ac06ca44481f515b74 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 17:37:42 +0800 Subject: [PATCH 099/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 7e3ca86b6e..5686b8e29a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -398,6 +398,9 @@ void destroyCliConnQTable(SCliConn* conn) { STransCtx* ctx = pIter; transCtxCleanup(ctx); pIter = taosHashIterate(conn->pQTable, pIter); + + transReleaseExHandle(transGetRefMgt(), *qid); + transRemoveExHandle(transGetRefMgt(), *qid); } taosHashCleanup(conn->pQTable); conn->pQTable = NULL; @@ -1037,7 +1040,7 @@ static void cliDestroy(uv_handle_t* handle) { int64_t* qid = taosHashGetKey(pIter, NULL); (void)taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); pIter = taosHashIterate(conn->pQTable, pIter); - tDebug("%s conn %p destroy state %ld", CONN_GET_INST_LABEL(conn), conn, *qid); + tDebug("%s conn %p destroy state %" PRId64 "", CONN_GET_INST_LABEL(conn), conn, *qid); } destroyCliConnQTable(conn); From ef0c301a6a1cf371e8eb374c8e67df8d6307845c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 18:05:30 +0800 Subject: [PATCH 100/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 38 +++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 5686b8e29a..74887663f4 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1507,8 +1507,7 @@ FORCE_INLINE int32_t cliBuildExceptResp(SCliThrd* pThrd, SCliReq* pReq, STransMs // handle noresp and inter manage msg if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { - destroyReq(pReq); - return 0; + return TSDB_CODE_RPC_NO_STATE; } if (pResp->code == 0) { pResp->code = TSDB_CODE_RPC_BROKEN_LINK; @@ -1613,21 +1612,29 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { int64_t qid = pReq->msg.info.qId; if (qid == 0) { return TSDB_CODE_RPC_NO_STATE; - } - - SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); - - if (pState == NULL) { - if (pReq->ctx == NULL) { - return TSDB_CODE_RPC_STATE_DROPED; - } - tDebug("%s conn %p failed to get statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); - return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { - *pConn = pState->conn; - tDebug("%s conn %p succ to get conn of statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + SExHandle* exh = transAcquireExHandle(transGetRefMgt(), qid); + if (exh == NULL) { + return TSDB_CODE_RPC_NO_STATE; + } + + SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); + + if (pState == NULL) { + if (pReq->ctx == NULL) { + transReleaseExHandle(transGetRefMgt(), qid); + return TSDB_CODE_RPC_STATE_DROPED; + } + tDebug("%s conn %p failed to get statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + transReleaseExHandle(transGetRefMgt(), qid); + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; + } else { + *pConn = pState->conn; + tDebug("%s conn %p succ to get conn of statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + } + transReleaseExHandle(transGetRefMgt(), qid); + return 0; } - return 0; } int32_t cliHandleState_mayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { @@ -1990,6 +1997,7 @@ int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { STrans* pInst = pThrd->pInst; int32_t code = cliBuildExceptResp(pThrd, pReq, pResp); if (code != 0) { + destroyReq(pReq); return code; } pInst->cfp(pInst->parent, pResp, NULL); From ff1ac62183dbc4d33e6ad75fed220769e31f7cdd Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 18:13:32 +0800 Subject: [PATCH 101/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 74887663f4..085e609961 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1615,7 +1615,7 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { } else { SExHandle* exh = transAcquireExHandle(transGetRefMgt(), qid); if (exh == NULL) { - return TSDB_CODE_RPC_NO_STATE; + return TSDB_CODE_RPC_STATE_DROPED; } SReqState* pState = taosHashGet(pThrd->pIdConnTable, &qid, sizeof(qid)); @@ -1667,9 +1667,7 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { if (code == 0) { (void)cliHandleState_mayUpdateStateCtx(pConn, pReq); } else if (code == TSDB_CODE_RPC_STATE_DROPED) { - STraceId* trace = &pReq->msg.info.traceId; - tWarn("%s failed to get statue, qid:%" PRId64 "", pInst->label, pReq->msg.info.qId); - destroyReq(pReq); + TAOS_CHECK_GOTO(code, &lino, _exception); return; } From b447c620e5d8b0175b0af7130e7a1d36c64537bb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 18:35:45 +0800 Subject: [PATCH 102/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 085e609961..65389b8bd0 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3192,11 +3192,15 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea } static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentNum, int32_t stateNum) { - int32_t total = reqNum + sentNum + stateNum; + int32_t total = reqNum + sentNum; if (total >= BUFFER_LIMIT) { return 1; } + if (stateNum >= BUFFER_LIMIT * 2) { + return 1; + } + return 0; } From 721d997c3855f39643af2a60711ff1b950044143 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 18:43:25 +0800 Subject: [PATCH 103/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 65389b8bd0..440b6a867c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3207,7 +3207,7 @@ static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentN static FORCE_INLINE bool filterToDebug(void* e, void* arg) { SCliReq* pReq = QUEUE_DATA(e, SCliReq, q); STraceId* trace = &pReq->msg.info.traceId; - tGWarn("%s is sent to, and no resp from server", pReq->msg.msgType); + tGWarn("%s is sent to, and no resp from server", TMSG_INFO(pReq->msg.msgType)); return false; } static FORCE_INLINE int32_t logConnMissHit(SCliConn* pConn) { From d6e7189201f65a7d83bcdbd41db5cfebe3055969 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 16 Sep 2024 18:45:18 +0800 Subject: [PATCH 104/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 440b6a867c..5513ea692b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3211,15 +3211,15 @@ static FORCE_INLINE bool filterToDebug(void* e, void* arg) { return false; } static FORCE_INLINE int32_t logConnMissHit(SCliConn* pConn) { - queue set; - QUEUE_INIT(&set); + // queue set; + // QUEUE_INIT(&set); pConn->heapMissHit++; tDebug("conn %p has %d reqs, %d sentout and %d status in process, total limit:%d, switch to other conn", pConn, transQueueSize(&pConn->reqsToSend), transQueueSize(&pConn->reqsSentOut), taosHashGetSize(pConn->pQTable), BUFFER_LIMIT); - if (transQueueSize(&pConn->reqsSentOut) >= BUFFER_LIMIT) { - transQueueRemoveByFilter(&pConn->reqsSentOut, filterToDebug, NULL, &set, 1); - } + // if (transQueueSize(&pConn->reqsSentOut) >= BUFFER_LIMIT) { + // transQueueRemoveByFilter(&pConn->reqsSentOut, filterToDebug, NULL, &set, 1); + // } return 0; } static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { From eb6053ffc50748b6944f281c5a7992680130e883 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 17 Sep 2024 09:44:11 +0800 Subject: [PATCH 105/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 8 ++++++-- source/libs/transport/src/transSvr.c | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 5513ea692b..54b73d14f7 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -889,6 +889,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { while (transReadComplete(pBuf)) { tTrace("%s conn %p read complete", CONN_GET_INST_LABEL(conn), conn); if (pBuf->invalid) { + conn->broken = true; transUnrefCliHandle(conn); return; break; @@ -1191,7 +1192,11 @@ bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msg int32_t cliBatchSend(SCliConn* pConn) { SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; - int32_t size = transQueueSize(&pConn->reqsToSend); + + if (pConn->broken) { + return 0; + } + int32_t size = transQueueSize(&pConn->reqsToSend); int32_t totalLen = 0; if (size == 0) { @@ -1263,7 +1268,6 @@ int32_t cliBatchSend(SCliConn* pConn) { TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); } - transRefCliHandle(pConn); uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 46bc1bfd2d..41038196d1 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -614,6 +614,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { if (true == pBuf->invalid || false == uvHandleReq(conn)) { tError("%s conn %p read invalid packet, received from %s, local info:%s", transLabel(pInst), conn, conn->dst, conn->src); + conn->broken = true; transUnrefSrvHandle(conn); return; } From 2184e4e8b1fc22aa8327ab1725a30e4581321dc5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 17 Sep 2024 11:21:47 +0800 Subject: [PATCH 106/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 54b73d14f7..31748ab031 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1264,8 +1264,8 @@ int32_t cliBatchSend(SCliConn* pConn) { pCliMsg->seq = pConn->seq; STraceId* trace = &pCliMsg->msg.info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%d, qid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), pConn, - TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); + tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%" PRId64 ", qid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), + pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); } transRefCliHandle(pConn); From 0faedf46691e2cfea0ed650ffa90a80c68f4cad5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 17 Sep 2024 11:22:31 +0800 Subject: [PATCH 107/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 31748ab031..f866097e2a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -604,8 +604,8 @@ void cliHandleResp(SCliConn* conn) { code = cliBuildRespFromCont(pReq, &resp, pHead); STraceId* trace = &resp.info.traceId; - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%d, qid:%" PRId64 "", CONN_GET_INST_LABEL(conn), - conn, TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%" PRId64 ", qid:%" PRId64 "", + CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); code = cliNotifyCb(conn, pReq, &resp); if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { From 3934898ffd63d654b5455f98bb6d0ca79d80ebc2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 17 Sep 2024 11:25:06 +0800 Subject: [PATCH 108/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transSvr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 41038196d1..12d243e3d1 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -682,8 +682,8 @@ void uvOnSendCb(uv_write_t* req, int status) { SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); STraceId* trace = &smsg->msg.info.traceId; - tGDebug("%s conn %p failed to send, seqNum:%d, qid:%" PRId64 ", reason:%s", transLabel(conn->pInst), conn, - smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); + tGDebug("%s conn %p failed to send, seqNum:%" PRId64 ", qid:%" PRId64 ", reason:%s", transLabel(conn->pInst), + conn, smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); destroySmsg(smsg); } @@ -753,8 +753,8 @@ static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { } STraceId* trace = &pMsg->info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d, seqNum:%d, qid:%" PRId64 "", transLabel(pInst), pConn, - TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, len, pMsg->info.seqNum, pMsg->info.qId); + tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d, seqNum:%" PRId64 ", qid:%" PRId64 "", transLabel(pInst), + pConn, TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, len, pMsg->info.seqNum, pMsg->info.qId); wb->base = (char*)pHead; wb->len = len; From 2db729583fd57f48b732a9d0ea4a3ecb7dbc3e24 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 18 Sep 2024 08:50:10 +0800 Subject: [PATCH 109/240] Merge branch '3.0' into enh/opt-transport --- source/libs/scheduler/src/schRemote.c | 2 +- source/libs/transport/src/transCli.c | 2 +- source/libs/transport/src/transSvr.c | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index bb06a25ce0..a1410f2421 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -503,7 +503,7 @@ int32_t schHandleDropCallback(void *param, SDataBuf *pMsg, int32_t code) { (void)rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT); // ignore error if (pMsg->handle == NULL) { - ASSERT(0); + qError("sch handle is NULL, may be already released and mem lea"); } if (pMsg) { taosMemoryFree(pMsg->pData); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f866097e2a..802af1aad1 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -557,7 +557,6 @@ void cliHandleResp(SCliConn* conn) { taosMemoryFree(pHead); tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb - // ASSERT(0); pThrd->notifyExceptCb(pThrd, NULL, NULL); return; } @@ -616,6 +615,7 @@ void cliHandleResp(SCliConn* conn) { if (cliMayRecycleConn(conn)) { return; } + cliConnCheckTimoutMsg(conn); cliConnMayUpdateTimer(conn, READ_TIMEOUT); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 12d243e3d1..612bbc8301 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -555,14 +555,14 @@ static bool uvHandleReq(SSvrConn* pConn) { } if (pHead->seqNum == 0) { - // ASSERT(0); + STraceId* trace = &pHead->traceId; + tGError("%s conn %p received invalid seqNum, msgType:%s", transLabel(pInst), pConn, TMSG_INFO(pHead->msgType)); + return false; } transMsg.info.handle = (void*)transAcquireExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId); transMsg.info.refIdMgt = pThrd->connRefMgt; - // ASSERTS(transMsg.info.handle != NULL, "trans-svr failed to alloc handle to msg"); - // pHead->noResp = 1, // 1. server application should not send resp on handle // 2. once send out data, cli conn released to conn pool immediately @@ -729,7 +729,6 @@ static int uvPrepareSendData(SSvrRespMsg* 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) { - // ASSERT(0); // (void)transQueuePop(&pConn->resps); // destroySmsg(smsg); // return TSDB_CODE_INVALID_MSG; From 4e1af260d153f14cc6342aef5a3dd5caf27dffe9 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 18 Sep 2024 08:52:39 +0800 Subject: [PATCH 110/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 802af1aad1..606212602e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -485,12 +485,12 @@ int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead code = taosHashRemove(conn->pQTable, &qId, sizeof(qId)); if (code != 0) { - tDebug("%s conn %p failed to release req %ld from conn", CONN_GET_INST_LABEL(conn), conn, qId); + tDebug("%s conn %p failed to release req:%" PRId64 " from conn", CONN_GET_INST_LABEL(conn), conn, qId); } code = taosHashRemove(pThrd->pIdConnTable, &qId, sizeof(qId)); if (code != 0) { - tDebug("%s conn %p failed to release req %ld from thrd ", CONN_GET_INST_LABEL(conn), conn, qId); + tDebug("%s conn %p failed to release req:%" PRId64 " from thrd ", CONN_GET_INST_LABEL(conn), conn, qId); } tDebug("%s %p reqToSend:%d, sentOut:%d", CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqsToSend), From bd69f7359743761c1ebb476f97083011b238cdd7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 18 Sep 2024 09:36:17 +0800 Subject: [PATCH 111/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 58 ++++++++++++++-------------- source/libs/transport/src/transSvr.c | 8 ++-- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 606212602e..e7fb1893cf 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -302,11 +302,11 @@ int32_t transHeapGet(SHeap* heap, SCliConn** p); int32_t transHeapInsert(SHeap* heap, SCliConn* p); int32_t transHeapDelete(SHeap* heap, SCliConn* p); -#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 { \ + uv_walk(loop, cliWalkCb, NULL); \ + (void)uv_run(loop, UV_RUN_DEFAULT); \ + (void)uv_loop_close(loop); \ } while (0); // snprintf may cause performance problem @@ -386,7 +386,7 @@ void cliConnMayUpdateTimer(SCliConn* conn, int timeout) { if (cliGetConnTimer(conn->hostThrd, conn) != 0) { return; } - uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); + (void)uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); } void cliHandleBatchResp(SCliConn* conn) { return; } @@ -399,8 +399,8 @@ void destroyCliConnQTable(SCliConn* conn) { transCtxCleanup(ctx); pIter = taosHashIterate(conn->pQTable, pIter); - transReleaseExHandle(transGetRefMgt(), *qid); - transRemoveExHandle(transGetRefMgt(), *qid); + (void)transReleaseExHandle(transGetRefMgt(), *qid); + (void)transRemoveExHandle(transGetRefMgt(), *qid); } taosHashCleanup(conn->pQTable); conn->pQTable = NULL; @@ -501,8 +501,8 @@ int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead transQueueRemoveByFilter(&conn->reqsSentOut, filterByQid, &qId, &set, -1); transQueueRemoveByFilter(&conn->reqsToSend, filterByQid, &qId, &set, -1); - transReleaseExHandle(transGetRefMgt(), qId); - transRemoveExHandle(transGetRefMgt(), qId); + (void)transReleaseExHandle(transGetRefMgt(), qId); + (void)transRemoveExHandle(transGetRefMgt(), qId); while (!QUEUE_IS_EMPTY(&set)) { queue* el = QUEUE_HEAD(&set); @@ -557,7 +557,7 @@ void cliHandleResp(SCliConn* conn) { taosMemoryFree(pHead); tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb - pThrd->notifyExceptCb(pThrd, NULL, NULL); + (void)pThrd->notifyExceptCb(pThrd, NULL, NULL); return; } @@ -802,7 +802,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { if (conn->status == ConnInPool) { return; } - uv_read_stop(conn->stream); + (void)uv_read_stop(conn->stream); SCliThrd* thrd = conn->hostThrd; cliResetConnTimer(conn); @@ -890,7 +890,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { tTrace("%s conn %p read complete", CONN_GET_INST_LABEL(conn), conn); if (pBuf->invalid) { conn->broken = true; - transUnrefCliHandle(conn); + (void)transUnrefCliHandle(conn); return; break; } else { @@ -911,7 +911,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), transGetRefCount(conn)); conn->broken = true; - transUnrefCliHandle(conn); + (void)transUnrefCliHandle(conn); } } @@ -925,8 +925,8 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) code = cliHandleState_mayUpdateState(pThrd, pReq, pConn); - addConnToHeapCache(pThrd->connHeapCache, pConn); - transQueuePush(&pConn->reqsToSend, &pReq->q); + (void)addConnToHeapCache(pThrd->connHeapCache, pConn); + (void)transQueuePush(&pConn->reqsToSend, &pReq->q); return cliDoConn(pThrd, pConn); _exception: // free conn @@ -993,7 +993,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int conn->bufSize = BUFFER_LIMIT; conn->buf = (uv_buf_t*)taosMemoryCalloc(1, BUFFER_LIMIT * sizeof(uv_buf_t)); - initWQ(&conn->wq); + (void)initWQ(&conn->wq); conn->stream->data = conn; conn->connReq.data = conn; @@ -1031,7 +1031,7 @@ static void cliDestroy(uv_handle_t* handle) { (void)transReleaseExHandle(transGetRefMgt(), conn->refId); (void)transRemoveExHandle(transGetRefMgt(), conn->refId); } - delConnFromHeapCache(pThrd->connHeapCache, conn); + (void)delConnFromHeapCache(pThrd->connHeapCache, conn); taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); taosMemoryFree(conn->ipStr); @@ -1155,7 +1155,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { cliConnRmReqs(conn); if (status != 0) { tDebug("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); - transUnrefCliHandle(conn); + (void)transUnrefCliHandle(conn); return; } @@ -1164,7 +1164,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); if (!cliMayRecycleConn(conn)) { - cliBatchSend(conn); + (void)cliBatchSend(conn); } } bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msgLen) { @@ -1266,18 +1266,18 @@ int32_t cliBatchSend(SCliConn* pConn) { STraceId* trace = &pCliMsg->msg.info.traceId; tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%" PRId64 ", qid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); - transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); + (void)transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); } transRefCliHandle(pConn); uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); - uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); + (void)uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); return 0; } int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; - transQueuePush(&pConn->reqsToSend, &pCliMsg->q); + (void)transQueuePush(&pConn->reqsToSend, &pCliMsg->q); code = cliBatchSend(pConn); return code; } @@ -1414,11 +1414,11 @@ void cliConnCb(uv_connect_t* req, int status) { if (status != 0) { tDebug("%s conn %p failed to connect to %s, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, uv_strerror(status)); - transUnrefCliHandle(pConn); + (void)transUnrefCliHandle(pConn); return; } pConn->connnected = 1; - cliConnSetSockInfo(pConn); + (void)cliConnSetSockInfo(pConn); tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); (void)cliBatchSend(pConn); @@ -1626,17 +1626,17 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { if (pState == NULL) { if (pReq->ctx == NULL) { - transReleaseExHandle(transGetRefMgt(), qid); + (void)transReleaseExHandle(transGetRefMgt(), qid); return TSDB_CODE_RPC_STATE_DROPED; } tDebug("%s conn %p failed to get statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); - transReleaseExHandle(transGetRefMgt(), qid); + (void)transReleaseExHandle(transGetRefMgt(), qid); return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { *pConn = pState->conn; tDebug("%s conn %p succ to get conn of statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } - transReleaseExHandle(transGetRefMgt(), qid); + (void)transReleaseExHandle(transGetRefMgt(), qid); return 0; } } @@ -3246,7 +3246,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int32_t stateNum = taosHashGetSize(pConn->pQTable); if (shouldSWitchToOtherConn(reqsNum, reqsSentOut, stateNum)) { - logConnMissHit(pConn); + (void)logConnMissHit(pConn); return NULL; } } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 612bbc8301..bdfa024026 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -463,7 +463,7 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { srvMsg->type = Normal; srvMsg->pConn = pConn; - transQueuePush(&pConn->resps, &srvMsg->q); + (void)transQueuePush(&pConn->resps, &srvMsg->q); uvStartSendRespImpl(srvMsg); taosMemoryFree(pHead); @@ -846,7 +846,7 @@ int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { return TSDB_CODE_RPC_NO_STATE; } else { transFreeMsg(p->msg.pCont); - taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); + (void)taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); } } return 0; @@ -859,7 +859,7 @@ static void uvStartSendResp(SSvrRespMsg* smsg) { return; } - transQueuePush(&pConn->resps, &smsg->q); + (void)transQueuePush(&pConn->resps, &smsg->q); uvStartSendRespImpl(smsg); return; } @@ -1087,7 +1087,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); - transSetConnOption((uv_tcp_t*)pConn->pTcp, 20); + (void)transSetConnOption((uv_tcp_t*)pConn->pTcp, 20); (void)uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); } else { From ea7178d714541cc9190dd416fa664793d64968a2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 18 Sep 2024 10:46:42 +0800 Subject: [PATCH 112/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/inc/transComm.h | 2 +- source/libs/transport/src/transCli.c | 2 +- source/libs/transport/src/transComm.c | 8 +++++--- source/libs/transport/src/transSvr.c | 11 ++++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index ea79e3582f..c8ce8e5f45 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -461,7 +461,7 @@ void transPrintEpSet(SEpSet* pEpSet); void transFreeMsg(void* msg); int32_t transCompressMsg(char* msg, int32_t len); -int32_t transDecompressMsg(char** msg, int32_t len); +int32_t transDecompressMsg(char** msg, int32_t* len); int32_t transOpenRefMgt(int size, void (*func)(void*)); void transCloseRefMgt(int32_t refMgt); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e7fb1893cf..e2f214a564 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -561,7 +561,7 @@ void cliHandleResp(SCliConn* conn) { return; } - if ((code = transDecompressMsg((char**)&pHead, msgLen)) < 0) { + if ((code = transDecompressMsg((char**)&pHead, &msgLen)) < 0) { tDebug("%s conn %p recv invalid packet, failed to decompress", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb return; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 060ab2edae..eb045f8e8a 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -59,7 +59,7 @@ int32_t transCompressMsg(char* msg, int32_t len) { taosMemoryFree(buf); return ret; } -int32_t transDecompressMsg(char** msg, int32_t len) { +int32_t transDecompressMsg(char** msg, int32_t* len) { STransMsgHead* pHead = (STransMsgHead*)(*msg); if (pHead->comp == 0) return 0; @@ -68,16 +68,18 @@ 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)); + int32_t tlen = *len; + char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead)); if (buf == NULL) { return terrno; } STransMsgHead* pNewHead = (STransMsgHead*)buf; int32_t decompLen = LZ4_decompress_safe(pCont + sizeof(STransCompMsg), (char*)pNewHead->content, - len - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen); + tlen - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen); memcpy((char*)pNewHead, (char*)pHead, sizeof(STransMsgHead)); + *len = oriLen + sizeof(STransMsgHead); pNewHead->msgLen = htonl(oriLen + sizeof(STransMsgHead)); taosMemoryFree(pHead); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index bdfa024026..7e86ef546f 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -510,6 +510,12 @@ static bool uvHandleReq(SSvrConn* pConn) { tError("%s conn %p read invalid packet", transLabel(pInst), pConn); return false; } + if (transDecompressMsg((char**)&pHead, &msgLen) < 0) { + tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); + taosMemoryFree(pHead); + return false; + } + if (uvConnMayGetUserInfo(pConn, &pHead, &msgLen) == true) { tDebug("%s conn %p get user info", transLabel(pInst), pConn); } @@ -518,11 +524,6 @@ static bool uvHandleReq(SSvrConn* pConn) { tTrace("%s conn %p not reset read buf", transLabel(pInst), pConn); } - if (transDecompressMsg((char**)&pHead, msgLen) < 0) { - tError("%s conn %p recv invalid packet, failed to decompress", transLabel(pInst), pConn); - taosMemoryFree(pHead); - return false; - } pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); From bffc70cd5af45c7b26f292ccfc979a5c152e1bd5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 18 Sep 2024 14:21:58 +0800 Subject: [PATCH 113/240] fix valid free --- source/libs/transport/src/transCli.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e2f214a564..8417c89565 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -682,7 +682,8 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { continue; } else { // already notify user - destroyReqWrapper(pReq, pThrd); + destroyReq(pReq); + // destroyReqWrapper(pReq, pThrd); } } From 88c07244688d61c74e700c744e2beaaf241b4081 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 18 Sep 2024 21:15:46 +0800 Subject: [PATCH 114/240] merge 3.0 --- source/libs/transport/src/transCli.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 8417c89565..16afa3628c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -405,20 +405,28 @@ void destroyCliConnQTable(SCliConn* conn) { taosHashCleanup(conn->pQTable); conn->pQTable = NULL; } + +typedef struct { + int64_t seq; + int32_t msgType; +} SFiterArg; + bool filteBySeq(void* key, void* arg) { - int64_t* seq = arg; - SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); - if (pReq->seq == *seq) { + SFiterArg* targ = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->seq == targ->seq && pReq->msg.msgType + 1 == targ->msgType) { return true; } else { return false; } } -int32_t cliGetReqBySeq(SCliConn* conn, int64_t seq, SCliReq** pReq) { +int32_t cliGetReqBySeq(SCliConn* conn, int64_t seq, int32_t msgType, SCliReq** pReq) { int32_t code = 0; queue set; QUEUE_INIT(&set) - transQueueRemoveByFilter(&conn->reqsSentOut, filteBySeq, &seq, &set, 1); + + SFiterArg arg = {.seq = seq, .msgType = msgType}; + transQueueRemoveByFilter(&conn->reqsSentOut, filteBySeq, &arg, &set, 1); if (QUEUE_IS_EMPTY(&set)) { return TSDB_CODE_OUT_OF_RANGE; @@ -578,7 +586,7 @@ void cliHandleResp(SCliConn* conn) { } return; } - code = cliGetReqBySeq(conn, seq, &pReq); + code = cliGetReqBySeq(conn, seq, pHead->msgType, &pReq); if (code == TSDB_CODE_OUT_OF_RANGE) { code = cliHandleState_mayCreateAhandle(conn, pHead, &resp); if (code == 0) { From 6d3b8c059462f96d7ff9a6c21b3e10fd5c35ce99 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 19 Sep 2024 09:04:56 +0800 Subject: [PATCH 115/240] opt transport --- source/libs/transport/inc/transComm.h | 20 ++++++--------- source/libs/transport/src/transCli.c | 35 +++++++++++++++------------ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index c8ce8e5f45..e75cd51fc0 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -139,30 +139,26 @@ typedef struct SCvtAddr { typedef struct { SEpSet epSet; // ip list provided by app SEpSet origEpSet; - void* ahandle; // handle provided by app - tmsg_t msgType; // message type - int8_t connType; // connection type cli/srv + void* ahandle; // handle provided by app + tmsg_t msgType; // message type STransCtx userCtx; // STransMsg* pRsp; // for synchronous API tsem_t* pSem; // for synchronous API STransSyncMsg* pSyncMsg; // for syncchronous with timeout API int64_t syncMsgRef; - SCvtAddr cvtAddr; + SCvtAddr* pCvtAddr; + int64_t retryInitTimestamp; + int64_t retryNextInterval; + int64_t retryMaxTimeout; int32_t retryMinInterval; int32_t retryMaxInterval; int32_t retryStepFactor; - int64_t retryMaxTimeout; - int64_t retryInitTimestamp; - int64_t retryNextInterval; - bool retryInit; int32_t retryStep; - int8_t epsetRetryCnt; int32_t retryCode; - - void* task; - int hThrdIdx; + int8_t retryInit; + int8_t epsetRetryCnt; } SReqCtx; #pragma pack(push, 1) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 16afa3628c..fd17e163b8 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -120,17 +120,13 @@ typedef struct { typedef struct SCliReq { SReqCtx* ctx; - STransMsg msg; queue q; STransMsgType type; + uint64_t st; + int64_t seq; + int32_t sent; //(0: no send, 1: alread sent) + STransMsg msg; - // int64_t refId; - uint64_t st; - int sent; //(0: no send, 1: alread sent) - queue seqq; - int64_t seq; - - queue qlist; } SCliReq; typedef struct SCliThrd { @@ -152,7 +148,7 @@ typedef struct SCliThrd { void (*destroyAhandleFp)(void* ahandle); SHashObj* fqdn2ipCache; - SCvtAddr cvtAddr; + SCvtAddr* pCvtAddr; SHashObj* failFastCache; SHashObj* batchCache; @@ -1474,12 +1470,18 @@ static void cliHandleQuit(SCliThrd* pThrd, SCliReq* pReq) { static void cliHandleRelease(SCliThrd* pThrd, SCliReq* pReq) { return; } static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { SReqCtx* pCtx = pReq->ctx; - pThrd->cvtAddr = pCtx->cvtAddr; + if (pThrd->pCvtAddr != NULL) { + taosMemoryFreeClear(pThrd->pCvtAddr); + } + pThrd->pCvtAddr = pCtx->pCvtAddr; destroyReq(pReq); return; } FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr) { + if (pCvtAddr == NULL) { + return 0; + } if (pCvtAddr->cvt == false) { if (EPSET_IS_VALID(pEpSet)) { return 0; @@ -2001,7 +2003,7 @@ int32_t initCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { if (pReq->ctx == NULL) { return 0; } - return cliMayCvtFqdnToIp(&pReq->ctx->epSet, &pThrd->cvtAddr); + return cliMayCvtFqdnToIp(&pReq->ctx->epSet, pThrd->pCvtAddr); } int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = thrd; @@ -2201,6 +2203,8 @@ static void destroyThrdObj(SCliThrd* pThrd) { taosHashCleanup(pThrd->pIdConnTable); + taosMemoryFree(pThrd->pCvtAddr); + taosMemoryFree(pThrd); } @@ -2426,7 +2430,7 @@ void cliRetryMayInitCtx(STrans* pInst, SCliReq* pReq) { pCtx->retryInitTimestamp = taosGetTimestampMs(); pCtx->retryNextInterval = pCtx->retryMinInterval; pCtx->retryStep = 0; - pCtx->retryInit = true; + pCtx->retryInit = 1; pCtx->retryCode = TSDB_CODE_SUCCESS; pReq->msg.info.handle = 0; } @@ -2756,7 +2760,6 @@ static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pRe pCliReq->msg = *pReq; pCliReq->st = taosGetTimestampUs(); pCliReq->type = Normal; - QUEUE_INIT(&pCliReq->seqq); *pCliMsg = pCliReq; @@ -3023,7 +3026,6 @@ int32_t transSendRecvWithTimeout(void* pInstRef, SEpSet* pEpSet, STransMsg* pReq pCliReq->msg = *pReq; pCliReq->st = taosGetTimestampUs(); pCliReq->type = Normal; - // pCliReq->refId = (int64_t)pInstRef; STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, @@ -3083,10 +3085,12 @@ int32_t transSetDefaultAddr(void* pInstRef, const char* ip, const char* fqdn) { break; } - pCtx->cvtAddr = cvtAddr; + pCtx->pCvtAddr = (SCvtAddr*)taosMemoryCalloc(1, sizeof(SCvtAddr)); + memcpy(pCtx->pCvtAddr, &cvtAddr, sizeof(SCvtAddr)); SCliReq* pReq = taosMemoryCalloc(1, sizeof(SCliReq)); if (pReq == NULL) { + taosMemoryFree(pCtx->pCvtAddr); taosMemoryFree(pCtx); code = terrno; break; @@ -3099,6 +3103,7 @@ int32_t transSetDefaultAddr(void* pInstRef, const char* ip, const char* fqdn) { tDebug("%s update epset at thread:%08" PRId64, pInst->label, thrd->pid); if ((code = transAsyncSend(thrd->asyncPool, &(pReq->q))) != 0) { + taosMemoryFree(pCtx->pCvtAddr); destroyReq(pReq); if (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT) { code = TSDB_CODE_RPC_MODULE_QUIT; From 03f30f721f480fe659072c4f458b9f67a68f6251 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 19 Sep 2024 09:47:48 +0800 Subject: [PATCH 116/240] fix invalid read --- source/libs/transport/src/transCli.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index fd17e163b8..026b7b2c91 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1057,11 +1057,10 @@ static void cliDestroy(uv_handle_t* handle) { } taosMemoryFree(conn->buf); - destroyWQ(&conn->wq); + (void)transDestroyBuffer(&conn->readBuf); tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); - (void)transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); } @@ -1114,6 +1113,8 @@ static void cliHandleException(SCliConn* conn) { destroyReq(pReq); } } + + QUEUE_REMOVE(&conn->q); if (conn->registered) { int8_t ref = transGetRefCount(conn); if (ref == 0 && !uv_is_closing((uv_handle_t*)conn->stream)) { From a5306b7133049fe8b22eb9c68dad2cf0a007a952 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 19 Sep 2024 09:49:46 +0800 Subject: [PATCH 117/240] fix invalid read/write --- source/libs/transport/src/transCli.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 026b7b2c91..17d8c819b8 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -181,9 +181,8 @@ typedef struct { // conn pool // add expire timeout and capacity limit -static void* createConnPool(int size); -static void* destroyConnPool(SCliThrd* thread); -// static SCliConn* getConnFromPool(SCliThrd* thread, char* key, bool* exceed); +static void* createConnPool(int size); +static void* destroyConnPool(SCliThrd* thread); static void addConnToPool(void* pool, SCliConn* conn); static void doCloseIdleConn(void* param); static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); @@ -816,6 +815,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { } conn->status = ConnInPool; + QUEUE_INIT(&conn->q); QUEUE_PUSH(&conn->list->conns, &conn->q); conn->list->size += 1; tDebug("conn %p added to pool, pool size: %d, dst: %s", conn, conn->list->size, conn->dstAddr); From 14df30671bf5511c06ef15a109466996d9df3088 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 19 Sep 2024 11:16:32 +0800 Subject: [PATCH 118/240] fix invalid read --- source/libs/transport/src/transCli.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 17d8c819b8..4bb6efaea5 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -280,6 +280,8 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); static void cliWalkCb(uv_handle_t* handle, void* arg); +static FORCE_INLINE int32_t destroyAllReqs(SCliConn* SCliConn); +static FORCE_INLINE bool filterAllReq(void* e, void* arg); typedef struct { void* p; HeapNode node; @@ -1032,6 +1034,8 @@ static void cliDestroy(uv_handle_t* handle) { SCliThrd* pThrd = conn->hostThrd; cliResetConnTimer(conn); + destroyAllReqs(conn); + if (conn->refId > 0) { (void)transReleaseExHandle(transGetRefMgt(), conn->refId); (void)transRemoveExHandle(transGetRefMgt(), conn->refId); @@ -1065,15 +1069,13 @@ static void cliDestroy(uv_handle_t* handle) { taosMemoryFree(conn); } -bool filterAllReq(void* e, void* arg) { return 1; } +static FORCE_INLINE bool filterAllReq(void* e, void* arg) { return 1; } -static void cliHandleException(SCliConn* conn) { +static FORCE_INLINE int32_t destroyAllReqs(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - - cliResetConnTimer(conn); - queue set; + queue set; QUEUE_INIT(&set); // TODO // 1. from qId from thread table @@ -1113,6 +1115,15 @@ static void cliHandleException(SCliConn* conn) { destroyReq(pReq); } } + return 0; +} +static void cliHandleException(SCliConn* conn) { + int32_t code = 0; + SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; + + cliResetConnTimer(conn); + destroyAllReqs(conn); QUEUE_REMOVE(&conn->q); if (conn->registered) { From 371e9075b7c6c22c36c60640e6cdc8c83f33c152 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 19 Sep 2024 13:02:36 +0800 Subject: [PATCH 119/240] fix invalid read --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4bb6efaea5..b85d5214fd 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1034,7 +1034,7 @@ static void cliDestroy(uv_handle_t* handle) { SCliThrd* pThrd = conn->hostThrd; cliResetConnTimer(conn); - destroyAllReqs(conn); + (void)destroyAllReqs(conn); if (conn->refId > 0) { (void)transReleaseExHandle(transGetRefMgt(), conn->refId); @@ -1123,7 +1123,7 @@ static void cliHandleException(SCliConn* conn) { STrans* pInst = pThrd->pInst; cliResetConnTimer(conn); - destroyAllReqs(conn); + (void)destroyAllReqs(conn); QUEUE_REMOVE(&conn->q); if (conn->registered) { From 045c4cd8fce41fff1fdd7cef075fec094935b2da Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 19 Sep 2024 13:30:27 +0800 Subject: [PATCH 120/240] update param --- source/libs/transport/inc/transComm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index e75cd51fc0..3b3af3d0de 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -492,7 +492,7 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pWhiteList, char** ppBuf); enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; -#define BUFFER_LIMIT 4 +#define BUFFER_LIMIT 1 #define HEAP_MISS_HIT_LIMIT 100000 #define READ_TIMEOUT 100000 From 6ca51aa0cd5c6975fea6ab517b61b2f00be0bb17 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 19 Sep 2024 13:35:56 +0800 Subject: [PATCH 121/240] Merge branch '3.0' into enh/opt-transport --- source/libs/transport/inc/transComm.h | 2 +- tests/script/tsim/tagindex/sma_and_tag_index.sim | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 3b3af3d0de..e75cd51fc0 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -492,7 +492,7 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pWhiteList, char** ppBuf); enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; -#define BUFFER_LIMIT 1 +#define BUFFER_LIMIT 4 #define HEAP_MISS_HIT_LIMIT 100000 #define READ_TIMEOUT 100000 diff --git a/tests/script/tsim/tagindex/sma_and_tag_index.sim b/tests/script/tsim/tagindex/sma_and_tag_index.sim index 77cc9f53f9..4a6a948e21 100644 --- a/tests/script/tsim/tagindex/sma_and_tag_index.sim +++ b/tests/script/tsim/tagindex/sma_and_tag_index.sim @@ -96,6 +96,7 @@ while $i < 5 sql drop index $sma endw +#sleep 5000 sql drop stable $mtPrefix sql select * from information_schema.ins_indexes if $rows != 0 then From 92fc12611bfcb2f6dbdc6463e138f11aff083b8e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 19 Sep 2024 19:53:15 +0800 Subject: [PATCH 122/240] fix invalid read --- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 6 +++--- source/libs/transport/src/transCli.c | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 060fce5808..65ed380067 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -392,7 +392,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.notWaitAvaliableConn = 0; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); - rpcInit.startReadTimer = 1; + rpcInit.startReadTimer = 0; pTrans->clientRpc = rpcOpen(&rpcInit); if (pTrans->clientRpc == NULL) { dError("failed to init dnode rpc client since:%s", tstrerror(terrno)); @@ -435,7 +435,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.supportBatch = 1; rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; - rpcInit.startReadTimer = 1; + rpcInit.startReadTimer = 0; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); pTrans->statusRpc = rpcOpen(&rpcInit); @@ -482,7 +482,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) { rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); - rpcInit.startReadTimer = 1; + rpcInit.startReadTimer = 0; pTrans->syncRpc = rpcOpen(&rpcInit); if (pTrans->syncRpc == NULL) { dError("failed to init dnode rpc sync client since %s", tstrerror(terrno)); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b85d5214fd..e6315761c7 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -657,6 +657,11 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { QUEUE_INIT(&set); SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; + + if (pInst->startReadTimer == 0) { + return; + } + if (transQueueSize(&conn->reqsSentOut) == 0) { return; } From 3740bf6851e429743ff5dabda10363f668fbad1f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 09:01:35 +0800 Subject: [PATCH 123/240] fix mem leak --- source/libs/transport/src/transCli.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e6315761c7..22a7ab7456 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1173,7 +1173,6 @@ static void cliBatchSendCb(uv_write_t* req, int status) { if (ref <= 0) { return; } - cliConnRmReqs(conn); if (status != 0) { tDebug("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); @@ -1293,7 +1292,12 @@ int32_t cliBatchSend(SCliConn* pConn) { transRefCliHandle(pConn); uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); - (void)uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); + int32_t ret = uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); + if (ret != 0) { + tError("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(ret)); + freeWReqToWQ(&pConn->wq, req->data); + transUnrefCliHandle(pConn); + } return 0; } From 7dc616194e51c02d40097fd2ee0f98f005da512f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 09:25:10 +0800 Subject: [PATCH 124/240] fix mem leak --- source/libs/transport/src/transSvr.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 7e86ef546f..db433d53a3 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -825,17 +825,20 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { transRefSrvHandle(pConn); - if (req == NULL) { - if (!uv_is_closing((uv_handle_t*)(pConn->pTcp))) { - tError("conn %p failed to write data, reason:%s", pConn, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - pConn->broken = true; - freeWReqToWQ(&pConn->wq, req->data); - taosMemoryFree(pWreq); - transUnrefSrvHandle(pConn); - return; + int32_t ret = uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); + if (ret != 0) { + tError("conn %p failed to write data, reason:%s", pConn, tstrerror(TSDB_CODE_OUT_OF_MEMORY), uv_err_name(ret)); + pConn->broken = true; + while (!QUEUE_IS_EMPTY(&pWreq->node)) { + queue* head = QUEUE_HEAD(&pWreq->node); + QUEUE_REMOVE(head); + SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); + destroySmsg(smsg); } + freeWReqToWQ(&pConn->wq, req->data); + + transUnrefSrvHandle(pConn); } - (void)uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); } int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { SSvrConn* pConn = pMsg->pConn; From 7c987fa740010751e17f16ab861a23cea184fd82 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 10:22:51 +0800 Subject: [PATCH 125/240] fix mem leak --- source/libs/transport/src/transSvr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index db433d53a3..e08d3f447f 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -827,7 +827,7 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { int32_t ret = uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); if (ret != 0) { - tError("conn %p failed to write data, reason:%s", pConn, tstrerror(TSDB_CODE_OUT_OF_MEMORY), uv_err_name(ret)); + tError("conn %p failed to write data, reason:%s", pConn, uv_err_name(ret)); pConn->broken = true; while (!QUEUE_IS_EMPTY(&pWreq->node)) { queue* head = QUEUE_HEAD(&pWreq->node); From 93702c8c41a8ce2c57e099fdf0b98f3bc633595e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 10:40:32 +0800 Subject: [PATCH 126/240] fix mem leak --- source/libs/transport/src/transCli.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 22a7ab7456..c347cc61cb 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2504,6 +2504,10 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { cliRetryMayInitCtx(pInst, pReq); + if (pReq->msg.info.qId != 0) { + return false; + } + if (!cliRetryShouldRetry(pInst, pResp)) { return false; } From 06edb735ea6458dc366c0d7ecc89c875b0d3e2d1 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 10:40:59 +0800 Subject: [PATCH 127/240] fix mem leak --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c347cc61cb..4cef50016e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2502,12 +2502,12 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { SReqCtx* pCtx = pReq->ctx; int32_t code = pResp->code; - cliRetryMayInitCtx(pInst, pReq); - if (pReq->msg.info.qId != 0) { return false; } + cliRetryMayInitCtx(pInst, pReq); + if (!cliRetryShouldRetry(pInst, pResp)) { return false; } From 51370c2c57cbd7acc5025e1c7cfb063b1f85dcd6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 10:44:08 +0800 Subject: [PATCH 128/240] fix mem leak --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4cef50016e..0f033315fa 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2502,7 +2502,7 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { SReqCtx* pCtx = pReq->ctx; int32_t code = pResp->code; - if (pReq->msg.info.qId != 0) { + if (pReq && pReq->msg.info.qId != 0) { return false; } From 6752f7690c4a18b02aaea8c065b60433465861ac Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 11:22:12 +0800 Subject: [PATCH 129/240] fix mem leak --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 0f033315fa..b00417e8f1 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1296,7 +1296,7 @@ int32_t cliBatchSend(SCliConn* pConn) { if (ret != 0) { tError("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(ret)); freeWReqToWQ(&pConn->wq, req->data); - transUnrefCliHandle(pConn); + (void)transUnrefCliHandle(pConn); } return 0; } @@ -1378,7 +1378,7 @@ _exception1: return code; _exception2: - transUnrefCliHandle(conn); + (void)transUnrefCliHandle(conn); tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, tstrerror(code)); return code; } From be412c3ca770eacc91651091f6d6077abcdeb85c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 15:24:00 +0800 Subject: [PATCH 130/240] fix compile error --- source/libs/transport/src/transCli.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b00417e8f1..96aeb20972 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -623,8 +623,6 @@ void cliHandleResp(SCliConn* conn) { cliConnCheckTimoutMsg(conn); cliConnMayUpdateTimer(conn, READ_TIMEOUT); - - (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); } void cliConnTimeout(uv_timer_t* handle) { @@ -813,7 +811,6 @@ static void addConnToPool(void* pool, SCliConn* conn) { if (conn->status == ConnInPool) { return; } - (void)uv_read_stop(conn->stream); SCliThrd* thrd = conn->hostThrd; cliResetConnTimer(conn); @@ -1182,7 +1179,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { cliConnMayUpdateTimer(conn, READ_TIMEOUT); - (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); if (!cliMayRecycleConn(conn)) { (void)cliBatchSend(conn); From 919de857d2dcfcd861f6fa5704099baa1986c6ea Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 15:37:15 +0800 Subject: [PATCH 131/240] fix invalid read --- source/libs/transport/src/transCli.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 96aeb20972..304729ee80 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -105,6 +105,7 @@ typedef struct SCliConn { uv_buf_t* buf; int32_t bufSize; + int32_t readerStart; queue wq; // uv_write_t queue } SCliConn; @@ -1178,8 +1179,12 @@ static void cliBatchSendCb(uv_write_t* req, int status) { } cliConnMayUpdateTimer(conn, READ_TIMEOUT); - - uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + // if (!uv_is_readable(conn->stream)) { + if (conn->readerStart == 0) { + uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + conn->readerStart = 1; + } + //} if (!cliMayRecycleConn(conn)) { (void)cliBatchSend(conn); From ea17b4a011d9cba8aa43bc729449e2e267e8d751 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 16:08:31 +0800 Subject: [PATCH 132/240] fix invalid read --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 304729ee80..b2a692298b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1181,7 +1181,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { cliConnMayUpdateTimer(conn, READ_TIMEOUT); // if (!uv_is_readable(conn->stream)) { if (conn->readerStart == 0) { - uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); conn->readerStart = 1; } //} From 5d50d1a6a0b560162efa3e383f2b3bea28a5483a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 20 Sep 2024 20:13:14 +0800 Subject: [PATCH 133/240] fix mem leak --- source/libs/transport/src/transCli.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b2a692298b..ea0096f7b2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -591,15 +591,13 @@ void cliHandleResp(SCliConn* conn) { code = cliBuildRespFromCont(NULL, &resp, pHead); code = cliNotifyCb(conn, NULL, &resp); return; - } else { - tDebug("%s conn %p recv unexpected packet, seqNum:%" PRId64 ",qid:%" PRId64 " reason:%s", - CONN_GET_INST_LABEL(conn), conn, seq, qId, tstrerror(code)); } if (code != 0) { tWarn("%s conn %p recv unexpected packet, msgType:%s, seqNum:%" PRId64 ", qId:%" PRId64 ", the sever may sends repeated response,reason:%s", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), seq, qId, tstrerror(code)); // TODO: notify cb + taosMemoryFree(pHead); if (cliMayRecycleConn(conn)) { return; } From 3d6c398fda69eca1bec654260bfcdaaa9fb547f2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 23 Sep 2024 10:53:55 +0800 Subject: [PATCH 134/240] fix invalid read --- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 65ed380067..20c5aa3118 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -239,7 +239,7 @@ _OVER: } if (IsReq(pRpc)) { - SRpcMsg rsp = {.code = code, .info = pRpc->info}; + SRpcMsg rsp = {.code = code, .info = pRpc->info, .msgType = pRpc->msgType + 1}; if (code == TSDB_CODE_MNODE_NOT_FOUND) { dmBuildMnodeRedirectRsp(pDnode, &rsp); } From 13a97f89d84fe62105e9f072834065388300ae56 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 23 Sep 2024 11:16:53 +0800 Subject: [PATCH 135/240] fix invalid read --- source/libs/transport/src/transComm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index eb045f8e8a..78c2f07b76 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -347,7 +347,7 @@ void transCtxInit(STransCtx* ctx) { ctx->args = taosHashInit(2, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); } void transCtxCleanup(STransCtx* ctx) { - if (ctx->args == NULL) { + if (ctx == NULL || ctx->args == NULL) { return; } From b3ad84d7cf0572a43ca497afbd6320e2bd80bb63 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 23 Sep 2024 14:13:56 +0800 Subject: [PATCH 136/240] fix invalid read --- source/libs/transport/src/transSvr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index e08d3f447f..31da79ada8 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1497,6 +1497,11 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, code = TSDB_CODE_OUT_OF_MEMORY; goto End; } + thrd->connRefMgt = transOpenRefMgt(50000, transDestroyExHandle); + if (thrd->connRefMgt < 0) { + code = thrd->connRefMgt; + goto End; + } srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); if (srv->pipe[i] == NULL) { From 97e60cefeed4809d119dc18b0f6ca704aad470b6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 23 Sep 2024 17:05:22 +0800 Subject: [PATCH 137/240] fix invalid timeout --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index ea0096f7b2..25badedd2d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -632,8 +632,8 @@ void cliConnTimeout(uv_timer_t* handle) { cliResetConnTimer(conn); return; } - tTrace("%s conn %p conn timeout", CONN_GET_INST_LABEL(conn), conn); + TAOS_UNUSED(transUnrefCliHandle(conn)); } bool filterToRmTimoutReq(void* key, void* arg) { @@ -1363,13 +1363,13 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); } + conn->registered = 1; transRefCliHandle(conn); ret = uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); if (ret != 0) { tError("%s conn %p failed to start timer, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception2); } - conn->registered = 1; return TSDB_CODE_RPC_ASYNC_IN_PROCESS; _exception1: From 54fc2bfe9e5639640420a4f38b826936af6eba1f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 23 Sep 2024 18:51:18 +0800 Subject: [PATCH 138/240] fix mem leak --- source/libs/transport/inc/transComm.h | 5 --- source/libs/transport/src/transCli.c | 47 ++++++++++++++++++--------- source/libs/transport/src/transComm.c | 33 ------------------- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index e75cd51fc0..0e809c06b0 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -350,11 +350,6 @@ typedef struct SWriteReq { void* conn; } SWriteReq; -void transReqQueueInit(queue* q); -void* transReqQueuePush(queue* q, SWriteReq* req); -void* transReqQueueRemove(void* arg); -void transReqQueueClear(queue* q); - // queue sending msgs typedef struct { queue node; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b4a998c88d..f02d5206db 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -110,15 +110,15 @@ typedef struct SCliConn { queue wq; // uv_write_t queue } SCliConn; -// #define TRANS_CONN_REF_INC(tconn) ((tconn) ? (tconn)->ref++ : 0) -// #define TRANS_CONN_REF_DEC(tconn) ((tconn) ? (tconn)->ref-- : 0) -// #define TRANS_CONN_REF_GET(tconn) ((tconn) ? (tconn)->ref : 0) - typedef struct { SCliConn* conn; void* arg; } SReqState; +typedef struct { + int64_t seq; + int32_t msgType; +} SFiterArg; typedef struct SCliReq { SReqCtx* ctx; queue q; @@ -282,7 +282,13 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); static void cliWalkCb(uv_handle_t* handle, void* arg); static FORCE_INLINE int32_t destroyAllReqs(SCliConn* SCliConn); -static FORCE_INLINE bool filterAllReq(void* e, void* arg); + +static FORCE_INLINE bool filterAllReq(void* e, void* arg); +static FORCE_INLINE bool filerBySeq(void* key, void* arg); +static FORCE_INLINE bool filterByQid(void* key, void* arg); +static FORCE_INLINE bool filterToDebug_timeoutMsg(void* key, void* arg); +static FORCE_INLINE bool filterToRmTimoutReq(void* key, void* arg); + typedef struct { void* p; HeapNode node; @@ -387,8 +393,6 @@ void cliConnMayUpdateTimer(SCliConn* conn, int timeout) { (void)uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); } -void cliHandleBatchResp(SCliConn* conn) { return; } - void destroyCliConnQTable(SCliConn* conn) { void* pIter = taosHashIterate(conn->pQTable, NULL); while (pIter != NULL) { @@ -404,12 +408,7 @@ void destroyCliConnQTable(SCliConn* conn) { conn->pQTable = NULL; } -typedef struct { - int64_t seq; - int32_t msgType; -} SFiterArg; - -bool filteBySeq(void* key, void* arg) { +static bool filteBySeq(void* key, void* arg) { SFiterArg* targ = arg; SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); if (pReq->seq == targ->seq && pReq->msg.msgType + 1 == targ->msgType) { @@ -632,6 +631,7 @@ void cliConnTimeout(uv_timer_t* handle) { cliResetConnTimer(conn); return; } + tTrace("%s conn %p conn timeout", CONN_GET_INST_LABEL(conn), conn); TAOS_UNUSED(transUnrefCliHandle(conn)); } @@ -642,8 +642,22 @@ bool filterToRmTimoutReq(void* key, void* arg) { int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000); if (elapse > READ_TIMEOUT) { return true; + } else { + return false; } - return true; + } + return false; +} + +bool filterToDebug_timeoutMsg(void* key, void* arg) { + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { + int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000); + if (elapse > READ_TIMEOUT) { + tWarn("req %s timeout, elapse:%" PRId64 "ms", TMSG_INFO(pReq->msg.msgType), elapse); + return false; + } + return false; } return false; } @@ -655,6 +669,8 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; + transQueueRemoveByFilter(&conn->reqsSentOut, filterToDebug_timeoutMsg, NULL, &set, -1); + if (pInst->startReadTimer == 0) { return; } @@ -663,6 +679,7 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { return; } + QUEUE_INIT(&set); transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmTimoutReq, NULL, &set, -1); while (!QUEUE_IS_EMPTY(&set)) { @@ -1177,12 +1194,10 @@ static void cliBatchSendCb(uv_write_t* req, int status) { } cliConnMayUpdateTimer(conn, READ_TIMEOUT); - // if (!uv_is_readable(conn->stream)) { if (conn->readerStart == 0) { (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); conn->readerStart = 1; } - //} if (!cliMayRecycleConn(conn)) { (void)cliBatchSend(conn); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index cdd8eea12c..a7ff04cc58 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -413,39 +413,6 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) { return ret; } -void transReqQueueInit(queue* q) { - // init req queue - QUEUE_INIT(q); -} -void* transReqQueuePush(queue* q, SWriteReq* userReq) { - return NULL; - // uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); - // req->data = userReq; - - // QUEUE_PUSH(q, &userReq->q); - // return req; -} -void* transReqQueueRemove(void* arg) { - return NULL; - // void* ret = NULL; - // uv_write_t* req = arg; - - // SWriteReq* userReq = req ? req->data : NULL; - // if (req == NULL) return NULL; - // QUEUE_REMOVE(&userReq->q); - - // return userReq; -} -void transReqQueueClear(queue* q) { - return; - // while (!QUEUE_IS_EMPTY(q)) { - // queue* h = QUEUE_HEAD(q); - // QUEUE_REMOVE(h); - // SWriteReq* req = QUEUE_DATA(h, SWriteReq, q); - // taosMemoryFree(req); - // } -} - int32_t transQueueInit(STransQueue* wq, void (*freeFunc)(void* arg)) { QUEUE_INIT(&wq->node); wq->freeFunc = (void (*)(void*))freeFunc; From f097de9fe02282578d9ced0b1a310bd28340f1c3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 23 Sep 2024 18:53:50 +0800 Subject: [PATCH 139/240] fix invalid timeout --- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 6 +++--- source/libs/transport/src/transCli.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index e29277fb7f..d0a7971794 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -398,7 +398,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.notWaitAvaliableConn = 0; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); - rpcInit.startReadTimer = 0; + rpcInit.startReadTimer = 1; pTrans->clientRpc = rpcOpen(&rpcInit); if (pTrans->clientRpc == NULL) { dError("failed to init dnode rpc client since:%s", tstrerror(terrno)); @@ -441,7 +441,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.supportBatch = 1; rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; - rpcInit.startReadTimer = 0; + rpcInit.startReadTimer = 1; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); pTrans->statusRpc = rpcOpen(&rpcInit); @@ -488,7 +488,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) { rpcInit.batchSize = 8 * 1024; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; (void)taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); - rpcInit.startReadTimer = 0; + rpcInit.startReadTimer = 1; pTrans->syncRpc = rpcOpen(&rpcInit); if (pTrans->syncRpc == NULL) { dError("failed to init dnode rpc sync client since %s", tstrerror(terrno)); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f02d5206db..e0411e2891 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -641,7 +641,7 @@ bool filterToRmTimoutReq(void* key, void* arg) { if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000); if (elapse > READ_TIMEOUT) { - return true; + return false; } else { return false; } From 2099a4554793a483821fa3f88b6cf1284e47f65e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 24 Sep 2024 15:42:18 +0800 Subject: [PATCH 140/240] fix invalid read --- source/libs/transport/inc/transComm.h | 9 ++++++++- source/libs/transport/src/transCli.c | 5 ++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 0e809c06b0..a903f26dc9 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -487,7 +487,14 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pWhiteList, char** ppBuf); enum { REQ_STATUS_INIT = 0, REQ_STATUS_PROCESSING }; -#define BUFFER_LIMIT 4 +#if defined(WINDOWS) || defined(DARWIN) +#define BUFFER_LIMIT 1 +#define STATE_BUFFER_LIMIT 1 +#else +#define BUFFER_LIMIT 4 +#define STATE_BUFFER_LIMIT 8 +#endif + #define HEAP_MISS_HIT_LIMIT 100000 #define READ_TIMEOUT 100000 diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e0411e2891..62c9529389 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3251,11 +3251,10 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentNum, int32_t stateNum) { int32_t total = reqNum + sentNum; - if (total >= BUFFER_LIMIT) { + if (stateNum >= STATE_BUFFER_LIMIT) { return 1; } - - if (stateNum >= BUFFER_LIMIT * 2) { + if (total >= BUFFER_LIMIT) { return 1; } From 72a40fabfc7f10e6f139b5771e9676d050d6b812 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 24 Sep 2024 16:37:02 +0800 Subject: [PATCH 141/240] update failure on windows --- source/libs/transport/src/transCli.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 62c9529389..99b6c87bd2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1232,6 +1232,10 @@ int32_t cliBatchSend(SCliConn* pConn) { if (pConn->broken) { return 0; } + + if (pConn->connnected != 1) { + return 0; + } int32_t size = transQueueSize(&pConn->reqsToSend); int32_t totalLen = 0; @@ -1319,6 +1323,7 @@ int32_t cliBatchSend(SCliConn* pConn) { int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; (void)transQueuePush(&pConn->reqsToSend, &pCliMsg->q); + code = cliBatchSend(pConn); return code; } From f534731cd9d49cf8962040962f79fbe13e6dffec Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 26 Sep 2024 22:02:58 +0800 Subject: [PATCH 142/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 47 +--------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index fd7db69afc..35276d49fe 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -91,7 +91,6 @@ typedef struct SCliConn { char* ipStr; int32_t port; - int64_t refId; int64_t seq; int8_t registered; @@ -216,8 +215,7 @@ SCliBatch* cliGetHeadFromList(SCliBatchList* pList); static void destroyCliConnQTable(SCliConn* conn); -static void cliHandleException(SCliConn* conn); -static int32_t allocConnRef(SCliConn* conn, bool update); +static void cliHandleException(SCliConn* conn); static int cliNotifyCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp); void cliResetConnTimer(SCliConn* conn); @@ -852,41 +850,6 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->task = transDQSched(thrd->timeoutQueue, doCloseIdleConn, arg, 10 * CONN_PERSIST_TIME(pInst->idleTime)); } } -static int32_t allocConnRef(SCliConn* conn, bool update) { - if (update) { - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); - conn->refId = -1; - } - - SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle)); - if (exh == NULL) { - return terrno; - } - - exh->refId = transAddExHandle(transGetRefMgt(), exh); - if (exh->refId < 0) { - taosMemoryFree(exh); - return TSDB_CODE_REF_INVALID_ID; - } - - QUEUE_INIT(&exh->q); - taosInitRWLatch(&exh->latch); - 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 < 0) { - taosMemoryFree(exh); - } - return 0; -} static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { SCliConn* conn = handle->data; @@ -997,7 +960,6 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int if (conn->pQTable == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _failed); } - TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); TAOS_CHECK_GOTO(cliGetConnTimer(pThrd, conn), &lino, _failed); @@ -1035,9 +997,6 @@ _failed: transQueueDestroy(&conn->reqsToSend); transQueueDestroy(&conn->reqsSentOut); taosMemoryFree(conn->dstAddr); - - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); } tError("failed to create conn, code:%d", code); taosMemoryFree(conn); @@ -1054,10 +1013,6 @@ static void cliDestroy(uv_handle_t* handle) { (void)destroyAllReqs(conn); - if (conn->refId > 0) { - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); - TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); - } (void)delConnFromHeapCache(pThrd->connHeapCache, conn); taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); From 34f86d96861d25b2b255436fa934521443433225 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 27 Sep 2024 09:41:26 +0800 Subject: [PATCH 143/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- include/libs/transport/trpc.h | 1 + source/libs/transport/src/transCli.c | 17 +++++++++----- source/libs/transport/src/transSvr.c | 33 ++++++++++------------------ 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 5d5dc00ad8..1fdf7db60a 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -132,6 +132,7 @@ typedef struct SRpcInit { int8_t shareConn; // 0: no share, 1. share int8_t notWaitAvaliableConn; // 1: wait to get, 0: no wait int8_t startReadTimer; + void *parent; } SRpcInit; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 35276d49fe..23048f4a7e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -263,7 +263,11 @@ static FORCE_INLINE void destroyReqAndAhanlde(void* cmsg); static FORCE_INLINE int cliRBChoseIdx(STrans* pInst); static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx); -int32_t cliHandleState_mayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn); +static int32_t cliHandleState_mayUpdateState(SCliConn* pConn, SCliReq* pReq); +static int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead); +static int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp); +static int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq); + int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); @@ -911,7 +915,7 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); - code = cliHandleState_mayUpdateState(pThrd, pReq, pConn); + code = cliHandleState_mayUpdateState(pConn, pReq); (void)addConnToHeapCache(pThrd->connHeapCache, pConn); (void)transQueuePush(&pConn->reqsToSend, &pReq->q); @@ -1648,9 +1652,10 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { } } -int32_t cliHandleState_mayUpdateState(SCliThrd* pThrd, SCliReq* pReq, SCliConn* pConn) { - int32_t code = 0; - int64_t qid = pReq->msg.info.qId; +int32_t cliHandleState_mayUpdateState(SCliConn* pConn, SCliReq* pReq) { + SCliThrd* pThrd = pConn->hostThrd; + int32_t code = 0; + int64_t qid = pReq->msg.info.qId; if (qid == 0) { return TSDB_CODE_RPC_NO_STATE; } @@ -1703,7 +1708,7 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { return; } } - code = cliHandleState_mayUpdateState(pThrd, pReq, pConn); + code = cliHandleState_mayUpdateState(pConn, pReq); } code = cliSendReq(pConn, pReq); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 864a65ebee..5be58cb5f4 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -437,8 +437,13 @@ static int8_t uvValidConn(SSvrConn* pConn) { static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { int32_t code = 0; STrans* pInst = pConn->pInst; - int64_t qId = taosHton64(pHead->qid); - if (pHead->msgType == TDMT_SCH_TASK_RELEASE && qId > 0) { + if (pHead->msgType == TDMT_SCH_TASK_RELEASE) { + int64_t qId = taosHton64(pHead->qid); + if (qId <= 0) { + tError("conn %p recv release, but invalid qid:%" PRId64 "", pConn, qId); + return TSDB_CODE_RPC_NO_STATE; + } + void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); if (p == NULL) { code = TSDB_CODE_RPC_NO_STATE; @@ -1644,22 +1649,8 @@ void uvHandleQuit(SSvrRespMsg* msg, SWorkThrd* thrd) { } taosMemoryFree(msg); } -void uvHandleRelease(SSvrRespMsg* msg, SWorkThrd* thrd) { - return; - // int32_t code = 0; - // SSvrConn* conn = msg->pConn; - // if (conn->status == ConnAcquire) { - // if (!transQueuePush(&conn->resps, msg)) { - // return; - // } - // uvStartSendRespImpl(msg); - // return; - // } else if (conn->status == ConnRelease || conn->status == ConnNormal) { - // tDebug("%s conn %p already released, ignore release-msg", transLabel(thrd->pInst), conn); - // } +void uvHandleRelease(SSvrRespMsg* msg, SWorkThrd* thrd) { return; } - // destroySmsg(msg); -} void uvHandleResp(SSvrRespMsg* msg, SWorkThrd* thrd) { // send msg to client tDebug("%s conn %p start to send resp (2/2)", transLabel(thrd->pInst), msg->pConn); @@ -1669,16 +1660,16 @@ void uvHandleResp(SSvrRespMsg* msg, SWorkThrd* thrd) { int32_t uvHandleStateReq(SSvrRespMsg* msg) { int32_t code = 0; SSvrConn* conn = msg->pConn; - tDebug("%s conn %p start to register brokenlink callback, qid:%" PRId64 "", transLabel(conn->pInst), conn, - msg->msg.info.qId); + int64_t qid = msg->msg.info.qId; + tDebug("%s conn %p start to register brokenlink callback, qid:%" PRId64 "", transLabel(conn->pInst), conn, qid); SSvrRegArg arg = {.notifyCount = 0, .init = 1, .msg = msg->msg}; - SSvrRegArg* p = taosHashGet(conn->pQTable, &msg->msg.info.qId, sizeof(msg->msg.info.qId)); + SSvrRegArg* p = taosHashGet(conn->pQTable, &qid, sizeof(qid)); if (p != NULL) { transFreeMsg(p->msg.pCont); } - code = taosHashPut(conn->pQTable, &msg->msg.info.qId, sizeof(msg->msg.info.qId), &arg, sizeof(arg)); + code = taosHashPut(conn->pQTable, &qid, sizeof(qid), &arg, sizeof(arg)); if (code == 0) tDebug("conn %p register brokenlink callback succ", conn); return code; } From 5fe588540f4a39324c7936aecffadbe4f59eb304 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 27 Sep 2024 10:08:34 +0800 Subject: [PATCH 144/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transSvr.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 5be58cb5f4..bdffd279e1 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -552,14 +552,6 @@ static bool uvHandleReq(SSvrConn* pConn) { transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; - if (transMsg.info.qId > 0) { - // int32_t code = taosHashPut(pConn->pQTable, &transMsg.info.qId, sizeof(int64_t), &transMsg, sizeof(STransMsg)); - // if (code != 0) { - // tError("%s conn %p failed to put msg to req dict, since %s", transLabel(pInst), pConn, tstrerror(code)); - // return false; - // } - } - if (pHead->seqNum == 0) { STraceId* trace = &pHead->traceId; tGError("%s conn %p received invalid seqNum, msgType:%s", transLabel(pInst), pConn, TMSG_INFO(pHead->msgType)); From 8b2754fe991d3cb7dd20e8f1638594e2399bab40 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 28 Sep 2024 13:39:24 +0800 Subject: [PATCH 145/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/inc/transComm.h | 12 +- source/libs/transport/src/trans.c | 9 +- source/libs/transport/src/transCli.c | 256 ++++++++++++++++++-------- source/libs/transport/src/transComm.c | 51 +++-- source/libs/transport/src/transSvr.c | 116 ++++++++---- 5 files changed, 300 insertions(+), 144 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index a903f26dc9..8b7311fe3b 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -297,7 +297,7 @@ bool transAsyncPoolIsEmpty(SAsyncPool* pool); int32_t transInitBuffer(SConnBuffer* buf); int32_t transClearBuffer(SConnBuffer* buf); -int32_t transDestroyBuffer(SConnBuffer* buf); +void transDestroyBuffer(SConnBuffer* buf); int32_t transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf); bool transReadComplete(SConnBuffer* connBuf); int32_t transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf); @@ -327,7 +327,7 @@ int32_t transRegisterMsg(const STransMsg* msg); int32_t transSetDefaultAddr(void* pInit, const char* ip, const char* fqdn); int32_t transSetIpWhiteList(void* pInit, void* arg, FilteFunc* func); -int32_t transSockInfo2Str(struct sockaddr* sockname, char* dst); +void transSockInfo2Str(struct sockaddr* sockname, char* dst); int32_t transAllocHandle(int64_t* refId); @@ -367,7 +367,7 @@ int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(void* arg)); * put arg into queue * if queue'size > 1, return false; else return true */ -int32_t transQueuePush(STransQueue* queue, void* arg); +void transQueuePush(STransQueue* queue, void* arg); /* * the size of queue */ @@ -457,9 +457,9 @@ int32_t transDecompressMsg(char** msg, int32_t* len); int32_t transOpenRefMgt(int size, void (*func)(void*)); void transCloseRefMgt(int32_t refMgt); int64_t transAddExHandle(int32_t refMgt, void* p); -int32_t transRemoveExHandle(int32_t refMgt, int64_t refId); +void transRemoveExHandle(int32_t refMgt, int64_t refId); void* transAcquireExHandle(int32_t refMgt, int64_t refId); -int32_t transReleaseExHandle(int32_t refMgt, int64_t refId); +void transReleaseExHandle(int32_t refMgt, int64_t refId); void transDestroyExHandle(void* handle); int32_t transGetRefMgt(); @@ -510,6 +510,8 @@ void destroyWQ(queue* wq); uv_write_t* allocWReqFromWQ(queue* wq, void* arg); void freeWReqToWQ(queue* wq, SWReqsWrapper* w); + +int32_t transSetReadOption(uv_handle_t* handle); #ifdef __cplusplus } #endif diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 6abca83f4c..a9ca9d47ce 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -131,13 +131,8 @@ void rpcClose(void* arg) { if (arg == NULL) { return; } - if (transRemoveExHandle(transGetInstMgt(), (int64_t)arg) != 0) { - tError("failed to remove rpc handle"); - } - - if (transReleaseExHandle(transGetInstMgt(), (int64_t)arg) != 0) { - tError("failed to release rpc handle"); - } + transRemoveExHandle(transGetInstMgt(), (int64_t)arg); + transReleaseExHandle(transGetInstMgt(), (int64_t)arg); tInfo("end to close rpc"); return; } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 23048f4a7e..3cf2f2c563 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -308,11 +308,11 @@ int32_t transHeapGet(SHeap* heap, SCliConn** p); int32_t transHeapInsert(SHeap* heap, SCliConn* p); int32_t transHeapDelete(SHeap* heap, SCliConn* p); -#define CLI_RELEASE_UV(loop) \ - do { \ - uv_walk(loop, cliWalkCb, NULL); \ - (void)uv_run(loop, UV_RUN_DEFAULT); \ - (void)uv_loop_close(loop); \ +#define CLI_RELEASE_UV(loop) \ + do { \ + uv_walk(loop, cliWalkCb, NULL); \ + (TAOS_UNUSED(uv_run(loop, UV_RUN_DEFAULT))); \ + (TAOS_UNUSED(uv_loop_close(loop))); \ } while (0); // snprintf may cause performance problem @@ -352,7 +352,11 @@ int32_t cliGetConnTimer(SCliThrd* pThrd, SCliConn* pConn) { return TSDB_CODE_OUT_OF_MEMORY; } tDebug("no available timer, create a timer %p", timer); - (void)uv_timer_init(pThrd->loop, timer); + int ret = uv_timer_init(pThrd->loop, timer); + if (ret != 0) { + tError("conn %p failed to init timer %p, ret:%d", pConn, timer, uv_err_name(ret)); + return TSDB_CODE_THIRDPARTY_ERROR; + } } timer->data = pConn; pConn->timer = timer; @@ -365,7 +369,10 @@ void cliResetConnTimer(SCliConn* conn) { tDebug("%s conn %p stop timer", CONN_GET_INST_LABEL(conn), conn); TAOS_UNUSED(uv_timer_stop(conn->timer)); } - (void)taosArrayPush(pThrd->timerList, &conn->timer); + if (taosArrayPush(pThrd->timerList, &conn->timer) == NULL) { + tError("%s conn %p failed to push timer %p to list since %s", CONN_GET_INST_LABEL(conn), conn, conn->timer, + tstrerror(terrno)); + } conn->timer->data = NULL; conn->timer = NULL; } @@ -392,19 +399,24 @@ void cliConnMayUpdateTimer(SCliConn* conn, int timeout) { if (cliGetConnTimer(conn->hostThrd, conn) != 0) { return; } - (void)uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); + int ret = uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); + if (ret != 0) { + tError("%s conn %p failed to start timer %p, ret:%d", CONN_GET_INST_LABEL(conn), conn, conn->timer, + uv_err_name(ret)); + } } void destroyCliConnQTable(SCliConn* conn) { - void* pIter = taosHashIterate(conn->pQTable, NULL); + int32_t code = 0; + void* pIter = taosHashIterate(conn->pQTable, NULL); while (pIter != NULL) { int64_t* qid = taosHashGetKey(pIter, NULL); STransCtx* ctx = pIter; transCtxCleanup(ctx); pIter = taosHashIterate(conn->pQTable, pIter); - (void)transReleaseExHandle(transGetRefMgt(), *qid); - (void)transRemoveExHandle(transGetRefMgt(), *qid); + transReleaseExHandle(transGetRefMgt(), *qid); + transRemoveExHandle(transGetRefMgt(), *qid); } taosHashCleanup(conn->pQTable); conn->pQTable = NULL; @@ -439,10 +451,15 @@ int32_t cliGetReqBySeq(SCliConn* conn, int64_t seq, int32_t msgType, SCliReq** p } int8_t cliMayRecycleConn(SCliConn* conn) { + int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && taosHashGetSize(conn->pQTable) == 0) { - (void)delConnFromHeapCache(pThrd->connHeapCache, conn); + code = delConnFromHeapCache(pThrd->connHeapCache, conn); + if (code != 0) { + tError("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, + tstrerror(code)); + } addConnToPool(pThrd->pool, conn); return 1; } @@ -508,8 +525,8 @@ int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead transQueueRemoveByFilter(&conn->reqsSentOut, filterByQid, &qId, &set, -1); transQueueRemoveByFilter(&conn->reqsToSend, filterByQid, &qId, &set, -1); - (void)transReleaseExHandle(transGetRefMgt(), qId); - (void)transRemoveExHandle(transGetRefMgt(), qId); + transReleaseExHandle(transGetRefMgt(), qId); + transRemoveExHandle(transGetRefMgt(), qId); while (!QUEUE_IS_EMPTY(&set)) { queue* el = QUEUE_HEAD(&set); @@ -562,9 +579,12 @@ void cliHandleResp(SCliConn* conn) { int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 0); if (msgLen < 0) { taosMemoryFree(pHead); - tDebug("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); + tWarn("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb - (void)pThrd->notifyExceptCb(pThrd, NULL, NULL); + code = pThrd->notifyExceptCb(pThrd, NULL, NULL); + if (code != 0) { + tError("%s conn %p failed to notify user since %s", tstrerror(code)); + } return; } @@ -864,16 +884,18 @@ static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_ } } static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { + int32_t code = 0; STUB_RAND_NETWORK_ERR(nread); if (handle->data == NULL) { return; } - int32_t fd; - (void)uv_fileno((uv_handle_t*)handle, &fd); - (void)taosSetSockOpt2(fd); SCliConn* conn = handle->data; + code = transSetReadOption((uv_handle_t*)handle); + if (code != 0) { + tWarn("%s conn %p failed to set recv opt since %s", CONN_GET_INST_LABEL(conn), conn, code); + } SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { @@ -882,7 +904,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { tTrace("%s conn %p read complete", CONN_GET_INST_LABEL(conn), conn); if (pBuf->invalid) { conn->broken = true; - (void)transUnrefCliHandle(conn); + TAOS_UNUSED(transUnrefCliHandle(conn)); return; break; } else { @@ -903,7 +925,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), transGetRefCount(conn)); conn->broken = true; - (void)transUnrefCliHandle(conn); + TAOS_UNUSED(transUnrefCliHandle(conn)); } } @@ -917,8 +939,11 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) code = cliHandleState_mayUpdateState(pConn, pReq); - (void)addConnToHeapCache(pThrd->connHeapCache, pConn); - (void)transQueuePush(&pConn->reqsToSend, &pReq->q); + code = addConnToHeapCache(pThrd->connHeapCache, pConn); + if (code != 0) { + TAOS_CHECK_GOTO(code, NULL, _exception); + } + transQueuePush(&pConn->reqsToSend, &pReq->q); return cliDoConn(pThrd, pConn); _exception: // free conn @@ -983,8 +1008,12 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int conn->bufSize = BUFFER_LIMIT; conn->buf = (uv_buf_t*)taosMemoryCalloc(1, BUFFER_LIMIT * sizeof(uv_buf_t)); + if (conn->buf == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _failed); + } + + TAOS_CHECK_GOTO(initWQ(&conn->wq), NULL, _failed); - (void)initWQ(&conn->wq); conn->stream->data = conn; conn->connReq.data = conn; @@ -993,11 +1022,11 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int return code; _failed: if (conn) { + taosMemoryFree(conn->buf); taosMemoryFree(conn->stream); - destroyCliConnQTable(conn); taosHashCleanup(conn->pQTable); - (void)transDestroyBuffer(&conn->readBuf); + transDestroyBuffer(&conn->readBuf); transQueueDestroy(&conn->reqsToSend); transQueueDestroy(&conn->reqsSentOut); taosMemoryFree(conn->dstAddr); @@ -1008,6 +1037,7 @@ _failed: } static void cliDestroyConn(SCliConn* conn, bool clear) { cliHandleException(conn); } static void cliDestroy(uv_handle_t* handle) { + int32_t code = 0; if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) { return; } @@ -1015,9 +1045,15 @@ static void cliDestroy(uv_handle_t* handle) { SCliThrd* pThrd = conn->hostThrd; cliResetConnTimer(conn); - (void)destroyAllReqs(conn); + code = destroyAllReqs(conn); + if (code != 0) { + tDebug("%s conn %p failed to all reqs since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } - (void)delConnFromHeapCache(pThrd->connHeapCache, conn); + code = delConnFromHeapCache(pThrd->connHeapCache, conn); + if (code != 0) { + tDebug("%s conn %p failed to del conn from heapcach since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); taosMemoryFree(conn->ipStr); @@ -1025,7 +1061,10 @@ static void cliDestroy(uv_handle_t* handle) { void* pIter = taosHashIterate(conn->pQTable, NULL); while (pIter) { int64_t* qid = taosHashGetKey(pIter, NULL); - (void)taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); + code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); + if (code != 0) { + tDebug("%s conn %p failed to remove state %" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, *qid, code); + } pIter = taosHashIterate(conn->pQTable, pIter); tDebug("%s conn %p destroy state %" PRId64 "", CONN_GET_INST_LABEL(conn), conn, *qid); } @@ -1039,7 +1078,7 @@ static void cliDestroy(uv_handle_t* handle) { taosMemoryFree(conn->buf); destroyWQ(&conn->wq); - (void)transDestroyBuffer(&conn->readBuf); + transDestroyBuffer(&conn->readBuf); tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); @@ -1100,7 +1139,10 @@ static void cliHandleException(SCliConn* conn) { STrans* pInst = pThrd->pInst; cliResetConnTimer(conn); - (void)destroyAllReqs(conn); + code = destroyAllReqs(conn); + if (code != 0) { + tError("%s conn %p failed to destroy all reqs on conn since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } QUEUE_REMOVE(&conn->q); if (conn->registered) { @@ -1134,6 +1176,7 @@ static void cliConnRmReqs(SCliConn* conn) { } static void cliBatchSendCb(uv_write_t* req, int status) { + int32_t code = 0; SWReqsWrapper* wrapper = (SWReqsWrapper*)req->data; SCliConn* conn = wrapper->arg; @@ -1148,18 +1191,27 @@ static void cliBatchSendCb(uv_write_t* req, int status) { cliConnRmReqs(conn); if (status != 0) { tDebug("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); - (void)transUnrefCliHandle(conn); + TAOS_UNUSED(transUnrefCliHandle(conn)); return; } cliConnMayUpdateTimer(conn, READ_TIMEOUT); if (conn->readerStart == 0) { - (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + code = uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + if (code != 0) { + tDebug("%s conn %p failed to start read since%s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(conn)); + return; + } conn->readerStart = 1; } if (!cliMayRecycleConn(conn)) { - (void)cliBatchSend(conn); + code = cliBatchSend(conn); + if (code != 0) { + tDebug("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(conn)); + } } } bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msgLen) { @@ -1265,7 +1317,7 @@ int32_t cliBatchSend(SCliConn* pConn) { STraceId* trace = &pCliMsg->msg.info.traceId; tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%" PRId64 ", qid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); - (void)transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); + transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); } transRefCliHandle(pConn); uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); @@ -1274,14 +1326,14 @@ int32_t cliBatchSend(SCliConn* pConn) { if (ret != 0) { tError("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(ret)); freeWReqToWQ(&pConn->wq, req->data); - (void)transUnrefCliHandle(pConn); + TAOS_UNUSED(transUnrefCliHandle(pConn)); } return 0; } int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { int32_t code = 0; - (void)transQueuePush(&pConn->reqsToSend, &pCliMsg->q); + transQueuePush(&pConn->reqsToSend, &pCliMsg->q); code = cliBatchSend(pConn); return code; @@ -1357,7 +1409,7 @@ _exception1: return code; _exception2: - (void)transUnrefCliHandle(conn); + TAOS_UNUSED(transUnrefCliHandle(conn)); tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, tstrerror(code)); return code; } @@ -1366,12 +1418,22 @@ int32_t cliConnSetSockInfo(SCliConn* pConn) { struct sockaddr peername, sockname; int addrlen = sizeof(peername); - (void)uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen); - (void)transSockInfo2Str(&peername, pConn->dst); + int32_t code = uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen); + if (code != 0) { + tWarn("failed to get perrname since %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + return code; + } + transSockInfo2Str(&peername, pConn->dst); addrlen = sizeof(sockname); - TAOS_UNUSED(uv_tcp_getsockname((uv_tcp_t*)pConn->stream, &sockname, &addrlen)); - TAOS_UNUSED(transSockInfo2Str(&sockname, pConn->src)); + code = uv_tcp_getsockname((uv_tcp_t*)pConn->stream, &sockname, &addrlen); + if (code != 0) { + tWarn("failed to get sock name since %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + return code; + } + transSockInfo2Str(&sockname, pConn->src); struct sockaddr_in addr = *(struct sockaddr_in*)&sockname; struct sockaddr_in saddr = *(struct sockaddr_in*)&peername; @@ -1399,6 +1461,7 @@ int32_t cliConnSetSockInfo(SCliConn* pConn) { bool filteGetAll(void* q, void* arg) { return true; } void cliConnCb(uv_connect_t* req, int status) { + int32_t code = 0; SCliConn* pConn = req->data; SCliThrd* pThrd = pConn->hostThrd; bool timeout = false; @@ -1419,14 +1482,24 @@ void cliConnCb(uv_connect_t* req, int status) { if (status != 0) { tDebug("%s conn %p failed to connect to %s, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, uv_strerror(status)); - (void)transUnrefCliHandle(pConn); + TAOS_UNUSED(transUnrefCliHandle(pConn)); return; } pConn->connnected = 1; - (void)cliConnSetSockInfo(pConn); + code = cliConnSetSockInfo(pConn); + if (code != 0) { + tDebug("%s conn %p failed to get sock info,reason:%s ", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, + tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(pConn)); + } tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); - (void)cliBatchSend(pConn); + code = cliBatchSend(pConn); + if (code != 0) { + tDebug("%s conn %p failed to get sock info,reason:%s ", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, + tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(pConn)); + } } static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code) { @@ -1637,17 +1710,17 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { if (pState == NULL) { if (pReq->ctx == NULL) { - (void)transReleaseExHandle(transGetRefMgt(), qid); + transReleaseExHandle(transGetRefMgt(), qid); return TSDB_CODE_RPC_STATE_DROPED; } tDebug("%s conn %p failed to get statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); - (void)transReleaseExHandle(transGetRefMgt(), qid); + transReleaseExHandle(transGetRefMgt(), qid); return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { *pConn = pState->conn; tDebug("%s conn %p succ to get conn of statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } - (void)transReleaseExHandle(transGetRefMgt(), qid); + transReleaseExHandle(transGetRefMgt(), qid); return 0; } } @@ -1668,7 +1741,7 @@ int32_t cliHandleState_mayUpdateState(SCliConn* pConn, SCliReq* pReq) { tDebug("%s conn %p succ to add statue, qid:%" PRId64 " (1)", transLabel(pThrd->pInst), pConn, qid); } - (void)cliHandleState_mayUpdateStateCtx(pConn, pReq); + TAOS_UNUSED(cliHandleState_mayUpdateStateCtx(pConn, pReq)); return code; } void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { @@ -1681,7 +1754,7 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { SCliConn* pConn = NULL; code = cliMayGetStateByQid(pThrd, pReq, &pConn); if (code == 0) { - (void)cliHandleState_mayUpdateStateCtx(pConn, pReq); + TAOS_UNUSED(cliHandleState_mayUpdateStateCtx(pConn, pReq)); } else if (code == TSDB_CODE_RPC_STATE_DROPED) { TAOS_CHECK_GOTO(code, &lino, _exception); return; @@ -1702,9 +1775,12 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { // do nothing, notiy return; } else if (code == 0) { - (void)addConnToHeapCache(pThrd->connHeapCache, pConn); + code = addConnToHeapCache(pThrd->connHeapCache, pConn); + if (code != 0) { + TAOS_CHECK_GOTO(code, &lino, _exception); + } } else { - // do nothing, notiy + TAOS_CHECK_GOTO(code, &lino, _exception); return; } } @@ -1719,7 +1795,11 @@ _exception: resp.code = code; STraceId* trace = &pReq->msg.info.traceId; tGWarn("%s failed to process req, reason:%s", pInst->label, tstrerror(code)); - (void)(pThrd->notifyExceptCb)(pThrd, pReq, &resp); + + code = (pThrd->notifyExceptCb)(pThrd, pReq, &resp); + if (code != 0) { + tGWarn("%s failed to notify user since %s", pInst->label, tstrerror(code)); + } return; } @@ -1948,7 +2028,7 @@ static void* cliWorkThread(void* arg) { pThrd->pid = taosGetSelfPthreadId(); tsEnableRandErr = true; - (void)strtolower(threadName, pThrd->pInst->label); + TAOS_UNUSED(strtolower(threadName, pThrd->pInst->label)); setThreadName(threadName); TAOS_UNUSED(uv_run(pThrd->loop, UV_RUN_DEFAULT)); @@ -2075,10 +2155,17 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { for (int i = 0; i < timerSize; i++) { uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); if (timer == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); + } + code = uv_timer_init(pThrd->loop, timer); + if (code != 0) { + tError("failed to init timer since %s", uv_err_name(code)); + code = TSDB_CODE_THIRDPARTY_ERROR; + TAOS_CHECK_GOTO(code, NULL, _end); + } + if (taosArrayPush(pThrd->timerList, &timer) == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _end); } - (void)uv_timer_init(pThrd->loop, timer); - (void)taosArrayPush(pThrd->timerList, &timer); } pThrd->pool = createConnPool(4); @@ -2137,7 +2224,7 @@ _end: TAOS_UNUSED(uv_loop_close(pThrd->loop)); taosMemoryFree(pThrd->loop); - (void)taosThreadMutexDestroy(&pThrd->msgMtx); + TAOS_UNUSED((taosThreadMutexDestroy(&pThrd->msgMtx))); transAsyncPoolDestroy(pThrd->asyncPool); for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); @@ -2169,7 +2256,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { } CLI_RELEASE_UV(pThrd->loop); - (void)taosThreadMutexDestroy(&pThrd->msgMtx); + TAOS_UNUSED(taosThreadMutexDestroy(&pThrd->msgMtx)); TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliReq, destroyReqWrapper, (void*)pThrd); transAsyncPoolDestroy(pThrd->asyncPool); @@ -2284,26 +2371,38 @@ static FORCE_INLINE void doCloseIdleConn(void* param) { taosMemoryFree(arg); } static FORCE_INLINE void cliPerfLog_schedMsg(SCliReq* pReq, char* label) { + int32_t code = 0; if (!(rpcDebugFlag & DEBUG_DEBUG)) { return; } SReqCtx* pCtx = pReq->ctx; STraceId* trace = &pReq->msg.info.traceId; char tbuf[512] = {0}; - (void)epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + + code = epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + if (code != 0) { + tWarn("failed to debug epset since %s", tstrerror(code)); + return; + } tGDebug("%s retry on next node,use:%s, step: %d,timeout:%" PRId64 "", label, tbuf, pCtx->retryStep, pCtx->retryNextInterval); return; } static FORCE_INLINE void cliPerfLog_epset(SCliConn* pConn, SCliReq* pReq) { + int32_t code = 0; if (!(rpcDebugFlag & DEBUG_TRACE)) { return; } SReqCtx* pCtx = pReq->ctx; char tbuf[512] = {0}; - (void)epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + + code = epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + if (code != 0) { + tWarn("failed to debug epset since %s", tstrerror(code)); + return; + } tTrace("%s conn %p extract epset from msg", CONN_GET_INST_LABEL(pConn), pConn); return; } @@ -2699,7 +2798,7 @@ static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t pThrd = exh->pThrd; taosWUnLockLatch(&exh->latch); - TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); + transReleaseExHandle(transGetRefMgt(), handle); return pThrd; } @@ -2806,16 +2905,16 @@ int32_t transSendRequest(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { destroyReq(pCliMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } int32_t transSendRequestWithId(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { @@ -2852,16 +2951,16 @@ int32_t transSendRequestWithId(void* pInstRef, const SEpSet* pEpSet, STransMsg* EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { destroyReq(pCliMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } @@ -2913,7 +3012,7 @@ int32_t transSendRecv(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STr SCliReq* pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); if (pCliReq == NULL) { - (void)tsem_destroy(sem); + (TAOS_UNUSED(tsem_destroy(sem))); taosMemoryFree(sem); taosMemoryFree(pCtx); TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); @@ -2940,11 +3039,11 @@ int32_t transSendRecv(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STr _RETURN: tsem_destroy(sem); taosMemoryFree(sem); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); taosMemoryFree(pTransRsp); return code; _RETURN1: - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); taosMemoryFree(pTransRsp); taosMemoryFree(pReq->pCont); pReq->pCont = NULL; @@ -3066,15 +3165,15 @@ int32_t transSendRecvWithTimeout(void* pInstRef, SEpSet* pEpSet, STransMsg* pReq } } _RETURN: - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); - (void)taosReleaseRef(transGetSyncMsgMgt(), ref); - (void)taosRemoveRef(transGetSyncMsgMgt(), ref); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + TAOS_UNUSED(taosReleaseRef(transGetSyncMsgMgt(), ref)); + TAOS_UNUSED(taosRemoveRef(transGetSyncMsgMgt(), ref)); return code; _RETURN2: transFreeMsg(pReq->pCont); pReq->pCont = NULL; taosMemoryFree(pTransMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } /* @@ -3128,7 +3227,7 @@ int32_t transSetDefaultAddr(void* pInstRef, const char* ip, const char* fqdn) { } } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return code; } @@ -3243,7 +3342,7 @@ static FORCE_INLINE bool filterToDebug(void* e, void* arg) { tGWarn("%s is sent to, and no resp from server", TMSG_INFO(pReq->msg.msgType)); return false; } -static FORCE_INLINE int32_t logConnMissHit(SCliConn* pConn) { +static FORCE_INLINE void logConnMissHit(SCliConn* pConn) { // queue set; // QUEUE_INIT(&set); pConn->heapMissHit++; @@ -3253,7 +3352,6 @@ static FORCE_INLINE int32_t logConnMissHit(SCliConn* pConn) { // if (transQueueSize(&pConn->reqsSentOut) >= BUFFER_LIMIT) { // transQueueRemoveByFilter(&pConn->reqsSentOut, filterToDebug, NULL, &set, 1); // } - return 0; } static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int code = 0; @@ -3275,7 +3373,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int32_t stateNum = taosHashGetSize(pConn->pQTable); if (shouldSWitchToOtherConn(reqsNum, reqsSentOut, stateNum)) { - (void)logConnMissHit(pConn); + logConnMissHit(pConn); return NULL; } } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 49f7c6e32b..59be5c4bde 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -97,13 +97,12 @@ void transFreeMsg(void* msg) { tTrace("rpc free cont:%p", (char*)msg - TRANS_MSG_OVERHEAD); taosMemoryFree((char*)msg - sizeof(STransMsgHead)); } -int transSockInfo2Str(struct sockaddr* sockname, char* dst) { +void transSockInfo2Str(struct sockaddr* sockname, char* dst) { struct sockaddr_in addr = *(struct sockaddr_in*)sockname; char buf[20] = {0}; int r = uv_ip4_name(&addr, (char*)buf, sizeof(buf)); sprintf(dst, "%s:%d", buf, ntohs(addr.sin_port)); - return r; } int32_t transInitBuffer(SConnBuffer* buf) { buf->buf = taosMemoryCalloc(1, BUFFER_CAP); @@ -118,10 +117,9 @@ int32_t transInitBuffer(SConnBuffer* buf) { buf->invalid = 0; return 0; } -int32_t transDestroyBuffer(SConnBuffer* p) { +void transDestroyBuffer(SConnBuffer* p) { taosMemoryFree(p->buf); p->buf = NULL; - return 0; } int32_t transClearBuffer(SConnBuffer* buf) { @@ -335,11 +333,12 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { SAsyncItem* item = async->data; if (taosThreadMutexLock(&item->mtx) != 0) { - tError("failed to lock mutex"); + tError("failed to lock mutex since %s", tstrerror(terrno)); + return terrno; } QUEUE_PUSH(&item->qmsg, q); - (void)taosThreadMutexUnlock(&item->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&item->mtx)); int ret = uv_async_send(async); if (ret != 0) { @@ -426,12 +425,10 @@ int32_t transQueueInit(STransQueue* wq, void (*freeFunc)(void* arg)) { wq->size = 0; return 0; } -int32_t transQueuePush(STransQueue* q, void* arg) { +void transQueuePush(STransQueue* q, void* arg) { queue* node = arg; QUEUE_PUSH(&q->node, node); q->size++; - - return 0; } void* transQueuePop(STransQueue* q) { if (q->size == 0) return NULL; @@ -737,18 +734,24 @@ int64_t transAddExHandle(int32_t refMgt, void* p) { // acquire extern handle return taosAddRef(refMgt, p); } -int32_t transRemoveExHandle(int32_t refMgt, int64_t refId) { +void transRemoveExHandle(int32_t refMgt, int64_t refId) { // acquire extern handle - return taosRemoveRef(refMgt, refId); + int32_t code = taosRemoveRef(refMgt, refId); + if (code != 0) { + tTrace("failed to remove %" PRId64 " from resetId:%d", refId, refMgt); + } } void* transAcquireExHandle(int32_t refMgt, int64_t refId) { // acquire extern handle return (void*)taosAcquireRef(refMgt, refId); } -int32_t transReleaseExHandle(int32_t refMgt, int64_t refId) { +void transReleaseExHandle(int32_t refMgt, int64_t refId) { // release extern handle - return taosReleaseRef(refMgt, refId); + int32_t code = taosReleaseRef(refMgt, refId); + if (code != 0) { + tTrace("failed to release %" PRId64 " from resetId:%d", refId, refMgt); + } } void transDestroyExHandle(void* handle) { if (handle == NULL) { @@ -869,15 +872,22 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) { // } int32_t initWQ(queue* wq) { + int32_t code = 0; QUEUE_INIT(wq); for (int i = 0; i < 4; i++) { SWReqsWrapper* w = taosMemoryCalloc(1, sizeof(SWReqsWrapper)); + if (w == NULL) { + TAOS_CHECK_GOTO(terrno, NULL, _exception); + } w->wreq.data = w; w->arg = NULL; QUEUE_INIT(&w->node); QUEUE_PUSH(wq, &w->q); } return 0; +_exception: + destroyWQ(wq); + return code; } void destroyWQ(queue* wq) { while (!QUEUE_IS_EMPTY(wq)) { @@ -899,6 +909,9 @@ uv_write_t* allocWReqFromWQ(queue* wq, void* arg) { return &w->wreq; } else { SWReqsWrapper* w = taosMemoryCalloc(1, sizeof(SWReqsWrapper)); + if (w == NULL) { + return NULL; + } w->wreq.data = w; w->arg = arg; QUEUE_INIT(&w->node); @@ -910,3 +923,15 @@ void freeWReqToWQ(queue* wq, SWReqsWrapper* w) { QUEUE_INIT(&w->node); QUEUE_PUSH(wq, &w->q); } + +int32_t transSetReadOption(uv_handle_t* handle) { + int32_t code = 0; + int32_t fd; + int ret = uv_fileno((uv_handle_t*)handle, &fd); + if (ret != 0) { + tWarn("failed to get fd since %s", uv_err_name(ret)); + return TSDB_CODE_THIRDPARTY_ERROR; + } + code = taosSetSockOpt2(fd); + return code; +} \ No newline at end of file diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 17a4de1737..4d1410bee1 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -161,8 +161,8 @@ static void uvFreeCb(uv_handle_t* handle); static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg); -static int uvPrepareSendData(SSvrRespMsg* msg, uv_buf_t* wb); -static void uvStartSendResp(SSvrRespMsg* msg); +static int32_t uvPrepareSendData(SSvrRespMsg* msg, uv_buf_t* wb); +static void uvStartSendResp(SSvrRespMsg* msg); static void uvNotifyLinkBrokenToApp(SSvrConn* conn); @@ -453,7 +453,10 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { (pInst->cfp)(pInst->parent, &(arg->msg), NULL); tTrace("conn %p recv release, notify server app, qid:%" PRId64 "", pConn, qId); - (void)taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); + code = taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); + if (code != 0) { + tDebug("conn %p failed to remove qid:%" PRId64 "", pConn, qId); + } tTrace("conn %p clear state,qid:%" PRId64 "", pConn, qId); } @@ -464,11 +467,15 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { .info.seqNum = taosHton64(pHead->seqNum)}; SSvrRespMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); + if (srvMsg == NULL) { + tError("conn %p recv release, but invalid qid:%" PRId64 "", pConn, qId); + return terrno; + } srvMsg->msg = tmsg; srvMsg->type = Normal; srvMsg->pConn = pConn; - (void)transQueuePush(&pConn->resps, &srvMsg->q); + transQueuePush(&pConn->resps, &srvMsg->q); uvStartSendRespImpl(srvMsg); taosMemoryFree(pHead); @@ -582,14 +589,16 @@ static bool uvHandleReq(SSvrConn* pConn) { pConnInfo->clientPort = pConn->port; tstrncpy(pConnInfo->user, pConn->user, sizeof(pConnInfo->user)); - (void)transReleaseExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId); + transReleaseExHandle(uvGetConnRefOfThrd(pThrd), pConn->refId); (*pInst->cfp)(pInst->parent, &transMsg, NULL); return true; } void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { + int32_t code = 0; SSvrConn* conn = cli->data; + STrans* pInst = conn->pInst; SWorkThrd* pThrd = conn->hostThrd; STUB_RAND_NETWORK_ERR(nread); @@ -599,10 +608,11 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { destroyConn(conn, true); return; } - STrans* pInst = conn->pInst; - int32_t fd = 0; - (void)uv_fileno((uv_handle_t*)cli, &fd); - (void)taosSetSockOpt2(fd); + + code = transSetReadOption((uv_handle_t*)cli); + if (code != 0) { + tWarn("%s conn %p failed to set recv opt since %s", transLabel(pInst), conn, code); + } SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { @@ -705,7 +715,7 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) { taosMemoryFree(req); } -static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { +static int32_t uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { SSvrConn* pConn = smsg->pConn; STransMsg* pMsg = &smsg->msg; if (pMsg->pCont == 0) { @@ -726,12 +736,10 @@ static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { pHead->withUserInfo = pConn->userInited == 0 ? 1 : 0; // handle invalid drop_task resp, TD-20098 - if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { - // (void)transQueuePop(&pConn->resps); - // destroySmsg(smsg); - // return TSDB_CODE_INVALID_MSG; - return 0; - } + // if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { + // // return TSDB_CODE_INVALID_MSG; + // return 0; + // } pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); // pHead->msgType = pMsg->msgType; @@ -758,6 +766,7 @@ static int uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { return 0; } static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* bufNum, queue* toSendQ) { + int32_t code = 0; int32_t size = transQueueSize(&pConn->resps); tDebug("%s conn %p has %d msg to send", transLabel(pConn->pInst), pConn, size); if (size == 0) { @@ -766,6 +775,9 @@ static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* buf if (pConn->bufSize < size) { pConn->buf = taosMemoryRealloc(pConn->buf, size * sizeof(uv_buf_t)); + if (pConn->buf == NULL) { + return terrno; + } pConn->bufSize = size; } uv_buf_t* pWb = pConn->buf; @@ -776,7 +788,10 @@ static int32_t uvBuildToSendData(SSvrConn* pConn, uv_buf_t** ppBuf, int32_t* buf queue* el = transQueuePop(&pConn->resps); SSvrRespMsg* pMsg = QUEUE_DATA(el, SSvrRespMsg, q); uv_buf_t wb; - (void)uvPrepareSendData(pMsg, &wb); + code = uvPrepareSendData(pMsg, &wb); + if (code != 0) { + return code; + } pWb[count] = wb; pMsg->sent = 1; QUEUE_PUSH(toSendQ, &pMsg->q); @@ -805,7 +820,12 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { return; } - uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); + uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); + if (req == NULL) { + uError("%s conn %p failed to alloc write req since %s", transLabel(pConn->pInst), pConn, tstrerror(terrno)); + transUnrefSrvHandle(pConn); + return; + } SWReqsWrapper* pWreq = req->data; uv_buf_t* pBuf = NULL; @@ -838,6 +858,7 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { } } int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { + int32_t code = 0; SSvrConn* pConn = pMsg->pConn; int64_t qid = pMsg->msg.info.qId; if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE && qid > 0) { @@ -847,7 +868,10 @@ int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { return TSDB_CODE_RPC_NO_STATE; } else { transFreeMsg(p->msg.pCont); - (void)taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); + code = taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); + if (code != 0) { + tError("%s conn %p failed release qid:%d since %s", tstrerror(code)); + } } } return 0; @@ -860,7 +884,7 @@ static void uvStartSendResp(SSvrRespMsg* smsg) { return; } - (void)transQueuePush(&pConn->resps, &smsg->q); + transQueuePush(&pConn->resps, &smsg->q); uvStartSendRespImpl(smsg); return; } @@ -928,12 +952,12 @@ void uvWorkerAsyncCb(uv_async_t* handle) { SExHandle* exh2 = transAcquireExHandle(uvGetConnRefOfThrd(pThrd), refId); if (exh2 == NULL || exh1 != exh2) { tTrace("handle except msg %p, ignore it", exh1); - (void)transReleaseExHandle(uvGetConnRefOfThrd(pThrd), refId); + transReleaseExHandle(uvGetConnRefOfThrd(pThrd), refId); destroySmsg(msg); continue; } msg->pConn = exh1->handle; - (void)transReleaseExHandle(uvGetConnRefOfThrd(pThrd), refId); + transReleaseExHandle(uvGetConnRefOfThrd(pThrd), refId); (*transAsyncHandle[msg->type])(msg, pThrd); } } @@ -1031,6 +1055,7 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { } } void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { + int32_t code = 0; STUB_RAND_NETWORK_ERR(nread); if (nread < 0) { if (nread != UV_EOF) { @@ -1100,9 +1125,16 @@ 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); - (void)transSetConnOption((uv_tcp_t*)pConn->pTcp, 20); - (void)uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); - + code = transSetConnOption((uv_tcp_t*)pConn->pTcp, 20); + if (code != 0) { + tWarn("failed to set tcp option since %s", tstrerror(code)); + } + code = uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); + if (code != 0) { + tWarn("%s conn %p failed to start to read since %s", uv_err_name(code)); + transUnrefSrvHandle(pConn); + return; + } } else { tDebug("failed to create new connection"); transUnrefSrvHandle(pConn); @@ -1225,10 +1257,14 @@ static int32_t addHandleToAcceptloop(void* arg) { } void* transWorkerThread(void* arg) { + int32_t code = 0; setThreadName("trans-svr-work"); SWorkThrd* pThrd = (SWorkThrd*)arg; tsEnableRandErr = true; - (void)uv_run(pThrd->loop, UV_RUN_DEFAULT); + code = uv_run(pThrd->loop, UV_RUN_DEFAULT); + if (code != 0) { + tWarn("failed to start to worker thread since %s", uv_err_name(code)); + } return NULL; } @@ -1318,7 +1354,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { _end: if (pConn) { transQueueDestroy(&pConn->resps); - (void)transDestroyBuffer(&pConn->readBuf); + transDestroyBuffer(&pConn->readBuf); taosHashCleanup(pConn->pQTable); taosMemoryFree(pConn->pTcp); destroyWQ(&pConn->wq); @@ -1369,8 +1405,8 @@ static void uvDestroyConn(uv_handle_t* handle) { } SWorkThrd* thrd = conn->hostThrd; - (void)transReleaseExHandle(uvGetConnRefOfThrd(thrd), conn->refId); - (void)transRemoveExHandle(uvGetConnRefOfThrd(thrd), conn->refId); + transReleaseExHandle(uvGetConnRefOfThrd(thrd), conn->refId); + transRemoveExHandle(uvGetConnRefOfThrd(thrd), conn->refId); STrans* pInst = thrd->pInst; tDebug("%s conn %p destroy", transLabel(pInst), conn); @@ -1383,7 +1419,7 @@ static void uvDestroyConn(uv_handle_t* handle) { uvConnDestroyAllState(conn); - (void)transDestroyBuffer(&conn->readBuf); + transDestroyBuffer(&conn->readBuf); destroyWQ(&conn->wq); taosMemoryFree(conn->buf); @@ -1839,15 +1875,15 @@ int32_t transReleaseSrvHandle(void* handle) { qId); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(info->refIdMgt, refId); + transReleaseExHandle(info->refIdMgt, refId); return code; } - (void)transReleaseExHandle(info->refIdMgt, refId); + transReleaseExHandle(info->refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to send to release handle", exh); - (void)transReleaseExHandle(info->refIdMgt, refId); + transReleaseExHandle(info->refIdMgt, refId); return code; _return2: tDebug("handle %p failed to send to release handle", exh); @@ -1893,17 +1929,17 @@ int32_t transSendResponse(const STransMsg* msg) { tGDebug("conn %p start to send resp (1/2)", exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(msg->info.refIdMgt, refId); + transReleaseExHandle(msg->info.refIdMgt, refId); return code; } - (void)transReleaseExHandle(msg->info.refIdMgt, refId); + transReleaseExHandle(msg->info.refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to send resp", exh); rpcFreeCont(msg->pCont); - (void)transReleaseExHandle(msg->info.refIdMgt, refId); + transReleaseExHandle(msg->info.refIdMgt, refId); return code; _return2: tDebug("handle %p failed to send resp", exh); @@ -1941,17 +1977,17 @@ int32_t transRegisterMsg(const STransMsg* msg) { tDebug("%s conn %p start to register brokenlink callback", transLabel(pInst), exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(msg->info.refIdMgt, refId); + transReleaseExHandle(msg->info.refIdMgt, refId); return code; } - (void)transReleaseExHandle(msg->info.refIdMgt, refId); + transReleaseExHandle(msg->info.refIdMgt, refId); return 0; _return1: tDebug("handle %p failed to register brokenlink", exh); rpcFreeCont(msg->pCont); - (void)transReleaseExHandle(msg->info.refIdMgt, refId); + transReleaseExHandle(msg->info.refIdMgt, refId); return code; _return2: tDebug("handle %p failed to register brokenlink", exh); @@ -1996,7 +2032,7 @@ int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { break; } } - TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)thandle)); + transReleaseExHandle(transGetInstMgt(), (int64_t)thandle); if (code != 0) { tError("ip-white-list update failed since %s", tstrerror(code)); From 886521619d7d7870ca6fa25b0e9aa44cae95670c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 28 Sep 2024 13:57:50 +0800 Subject: [PATCH 146/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 14 ++++++-------- source/libs/transport/src/transSvr.c | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3cf2f2c563..6156f224db 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -401,7 +401,7 @@ void cliConnMayUpdateTimer(SCliConn* conn, int timeout) { } int ret = uv_timer_start(conn->timer, cliConnTimeout__checkReq, timeout, 0); if (ret != 0) { - tError("%s conn %p failed to start timer %p, ret:%d", CONN_GET_INST_LABEL(conn), conn, conn->timer, + tError("%s conn %p failed to start timer %p since %s", CONN_GET_INST_LABEL(conn), conn, conn->timer, uv_err_name(ret)); } } @@ -579,11 +579,11 @@ void cliHandleResp(SCliConn* conn) { int32_t msgLen = transDumpFromBuffer(&conn->readBuf, (char**)&pHead, 0); if (msgLen < 0) { taosMemoryFree(pHead); - tWarn("%s conn %p recv invalid packet ", CONN_GET_INST_LABEL(conn), conn); + tWarn("%s conn %p recv invalid packet", CONN_GET_INST_LABEL(conn), conn); // TODO: notify cb code = pThrd->notifyExceptCb(pThrd, NULL, NULL); if (code != 0) { - tError("%s conn %p failed to notify user since %s", tstrerror(code)); + tError("%s conn %p failed to notify user since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); } return; } @@ -894,7 +894,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { SCliConn* conn = handle->data; code = transSetReadOption((uv_handle_t*)handle); if (code != 0) { - tWarn("%s conn %p failed to set recv opt since %s", CONN_GET_INST_LABEL(conn), conn, code); + tWarn("%s conn %p failed to set recv opt since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); } SConnBuffer* pBuf = &conn->readBuf; @@ -1488,16 +1488,14 @@ void cliConnCb(uv_connect_t* req, int status) { pConn->connnected = 1; code = cliConnSetSockInfo(pConn); if (code != 0) { - tDebug("%s conn %p failed to get sock info,reason:%s ", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, - tstrerror(code)); + tDebug("%s conn %p failed to get sock info since %s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); TAOS_UNUSED(transUnrefCliHandle(pConn)); } tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); code = cliBatchSend(pConn); if (code != 0) { - tDebug("%s conn %p failed to get sock info,reason:%s ", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, - tstrerror(code)); + tDebug("%s conn %p failed to get sock info since %s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); TAOS_UNUSED(transUnrefCliHandle(pConn)); } } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 4d1410bee1..e2d0405e1f 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -611,7 +611,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { code = transSetReadOption((uv_handle_t*)cli); if (code != 0) { - tWarn("%s conn %p failed to set recv opt since %s", transLabel(pInst), conn, code); + tWarn("%s conn %p failed to set recv opt since %s", transLabel(pInst), conn, tstrerror(code)); } SConnBuffer* pBuf = &conn->readBuf; @@ -870,7 +870,7 @@ int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { transFreeMsg(p->msg.pCont); code = taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); if (code != 0) { - tError("%s conn %p failed release qid:%d since %s", tstrerror(code)); + tError("%s conn %p failed release qid:%d since %s", transLabel(pConn->pInst), pConn, tstrerror(code)); } } } From 1402942f35d35d0d26a4db6dfc21c22bdfabeb34 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 28 Sep 2024 14:04:42 +0800 Subject: [PATCH 147/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 5 +++-- source/libs/transport/src/transSvr.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 6156f224db..af765ca112 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -354,7 +354,7 @@ int32_t cliGetConnTimer(SCliThrd* pThrd, SCliConn* pConn) { tDebug("no available timer, create a timer %p", timer); int ret = uv_timer_init(pThrd->loop, timer); if (ret != 0) { - tError("conn %p failed to init timer %p, ret:%d", pConn, timer, uv_err_name(ret)); + tError("conn %p failed to init timer %p since %s", pConn, timer, uv_err_name(ret)); return TSDB_CODE_THIRDPARTY_ERROR; } } @@ -1063,7 +1063,8 @@ static void cliDestroy(uv_handle_t* handle) { int64_t* qid = taosHashGetKey(pIter, NULL); code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); if (code != 0) { - tDebug("%s conn %p failed to remove state %" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, *qid, code); + tDebug("%s conn %p failed to remove state %" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, *qid, + tstrerror(code)); } pIter = taosHashIterate(conn->pQTable, pIter); tDebug("%s conn %p destroy state %" PRId64 "", CONN_GET_INST_LABEL(conn), conn, *qid); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index e2d0405e1f..69e4bdd485 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -870,7 +870,8 @@ int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { transFreeMsg(p->msg.pCont); code = taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); if (code != 0) { - tError("%s conn %p failed release qid:%d since %s", transLabel(pConn->pInst), pConn, tstrerror(code)); + tError("%s conn %p failed to release qid:%" PRId64 " since %s", transLabel(pConn->pInst), pConn, qid, + tstrerror(code)); } } } @@ -1131,7 +1132,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { } code = uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); if (code != 0) { - tWarn("%s conn %p failed to start to read since %s", uv_err_name(code)); + tWarn("conn %p failed to start to read since %s", pConn, uv_err_name(code)); transUnrefSrvHandle(pConn); return; } From 079f757ebba67865de632ef74096e44fcc6ce951 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 28 Sep 2024 15:56:58 +0800 Subject: [PATCH 148/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index af765ca112..7fe64c8a26 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1776,10 +1776,10 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { } else if (code == 0) { code = addConnToHeapCache(pThrd->connHeapCache, pConn); if (code != 0) { - TAOS_CHECK_GOTO(code, &lino, _exception); + tWarn("%s conn %p failed to added to heap cache since %s", pInst->label, tstrerror(code)); } } else { - TAOS_CHECK_GOTO(code, &lino, _exception); + // TAOS_CHECK_GOTO(code, &lino, _exception); return; } } From 88222b5e868daa3e70c995d0d88344c37def6693 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 08:11:44 +0800 Subject: [PATCH 149/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 7fe64c8a26..80f6e80c73 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1776,7 +1776,7 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { } else if (code == 0) { code = addConnToHeapCache(pThrd->connHeapCache, pConn); if (code != 0) { - tWarn("%s conn %p failed to added to heap cache since %s", pInst->label, tstrerror(code)); + tWarn("%s conn %p failed to added to heap cache since %s", pInst->label, pConn, tstrerror(code)); } } else { // TAOS_CHECK_GOTO(code, &lino, _exception); From 22f0d9b793b47773bb747755c67307fb538abfb5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 08:24:50 +0800 Subject: [PATCH 150/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 80f6e80c73..4599a2d6f3 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1238,6 +1238,7 @@ bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msg return true; } int32_t cliBatchSend(SCliConn* pConn) { + int32_t code = 0; SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; @@ -1257,10 +1258,12 @@ int32_t cliBatchSend(SCliConn* pConn) { } uv_buf_t* wb = NULL; if (pConn->bufSize < size) { - pConn->buf = taosMemoryRealloc(pConn->buf, size * sizeof(uv_buf_t)); + uv_buf_t* twb = (uv_buf_t*)taosMemoryRealloc(pConn->buf, size * sizeof(uv_buf_t)); + if (twb == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pConn->buf = twb; pConn->bufSize = size; - taosMemoryFree(wb); - return TSDB_CODE_OUT_OF_MEMORY; } wb = pConn->buf; @@ -1275,6 +1278,9 @@ int32_t cliBatchSend(SCliConn* pConn) { STransMsg* pReq = (STransMsg*)(&pCliMsg->msg); if (pReq->pCont == 0) { pReq->pCont = (void*)rpcMallocCont(0); + if (pReq->pCont == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } pReq->contLen = 0; } @@ -1327,17 +1333,16 @@ int32_t cliBatchSend(SCliConn* pConn) { if (ret != 0) { tError("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(ret)); freeWReqToWQ(&pConn->wq, req->data); + code = TSDB_CODE_THIRDPARTY_ERROR; TAOS_UNUSED(transUnrefCliHandle(pConn)); } - return 0; + return code; } int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { - int32_t code = 0; transQueuePush(&pConn->reqsToSend, &pCliMsg->q); - code = cliBatchSend(pConn); - return code; + return cliBatchSend(pConn); } static void cliDestroyBatch(SCliBatch* pBatch) { @@ -1786,6 +1791,10 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { code = cliHandleState_mayUpdateState(pConn, pReq); } code = cliSendReq(pConn, pReq); + if (code != 0) { + tWarn("%s conn %p failed to send req since %s", pInst->label, pConn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(pConn)); + } tTrace("%s conn %p ready", pInst->label, pConn); return; From 08f962a1d6b321b09cd8d631e67e68420af2d99a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 08:59:15 +0800 Subject: [PATCH 151/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- include/libs/transport/trpc.h | 6 +-- source/client/src/clientEnv.c | 1 + source/dnode/mgmt/node_mgmt/src/dmTransport.c | 7 ++-- source/libs/transport/inc/transportInt.h | 2 +- source/libs/transport/src/trans.c | 5 ++- source/libs/transport/src/transCli.c | 41 +++++++++++-------- source/libs/transport/src/transSvr.c | 10 +++-- source/libs/transport/test/cliBench.c | 2 +- 8 files changed, 44 insertions(+), 30 deletions(-) diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 1fdf7db60a..2f6b23a594 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -128,12 +128,12 @@ typedef struct SRpcInit { int32_t connLimitLock; int32_t timeToGetConn; int8_t supportBatch; // 0: no batch, 1. batch - int32_t batchSize; + int32_t shareConnLimit; int8_t shareConn; // 0: no share, 1. share int8_t notWaitAvaliableConn; // 1: wait to get, 0: no wait int8_t startReadTimer; - - void *parent; + + void *parent; } SRpcInit; typedef struct { diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 3b755c2921..2ced1a6ac5 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -370,6 +370,7 @@ int32_t openTransporter(const char *user, const char *auth, int32_t numOfThread, connLimitNum = TMAX(connLimitNum, 10); connLimitNum = TMIN(connLimitNum, 1000); rpcInit.connLimitNum = connLimitNum; + rpcInit.shareConnLimit = 8; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; int32_t code = taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index dd06be8b0b..b0e36a153c 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -404,7 +404,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.batchSize = 8 * 1024; + rpcInit.shareConnLimit = 16; rpcInit.shareConn = 1; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.notWaitAvaliableConn = 0; @@ -454,7 +454,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.batchSize = 8 * 1024; + rpcInit.shareConnLimit = 32; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.startReadTimer = 1; @@ -503,7 +503,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.batchSize = 8 * 1024; + rpcInit.shareConnLimit = 64; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.startReadTimer = 1; @@ -560,6 +560,7 @@ int32_t dmInitServer(SDnode *pDnode) { rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.parent = pDnode; rpcInit.compressSize = tsCompressMsgSize; + rpcInit.shareConnLimit = 16; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); diff --git a/source/libs/transport/inc/transportInt.h b/source/libs/transport/inc/transportInt.h index 8e10357f07..cf0ccd9fb2 100644 --- a/source/libs/transport/inc/transportInt.h +++ b/source/libs/transport/inc/transportInt.h @@ -70,7 +70,7 @@ typedef struct { int32_t connLimitNum; int8_t connLimitLock; // 0: no lock. 1. lock int8_t supportBatch; // 0: no batch, 1: support batch - int32_t batchSize; + int32_t shareConnLimit; int8_t optBatchFetch; int32_t timeToGetConn; int index; diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index a9ca9d47ce..862f3d0adb 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -79,7 +79,10 @@ void* rpcOpen(const SRpcInit* pInit) { pRpc->connLimitLock = pInit->connLimitLock; pRpc->supportBatch = pInit->supportBatch; - pRpc->batchSize = pInit->batchSize; + pRpc->shareConnLimit = pInit->shareConnLimit; + if (pRpc->shareConnLimit <= 0) { + pRpc->shareConnLimit = BUFFER_LIMIT; + } pRpc->numOfThreads = pInit->numOfThreads > TSDB_MAX_RPC_THREADS ? TSDB_MAX_RPC_THREADS : pInit->numOfThreads; if (pRpc->numOfThreads <= 0) { diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4599a2d6f3..9c2ece635f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -48,7 +48,7 @@ typedef struct { queue wq; queue listq; int32_t wLen; - int32_t batchSize; // + int32_t shareConnLimit; // int32_t batch; SCliBatchList* pList; } SCliBatch; @@ -961,6 +961,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int int32_t code = 0; int32_t lino = 0; + STrans* pInst = pThrd->pInst; SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn)); if (conn == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _failed); @@ -971,6 +972,9 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int conn->dstAddr = taosStrdup(addr); conn->ipStr = taosStrdup(ip); conn->port = port; + if (conn->dstAddr == NULL || conn->ipStr == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _failed); + } conn->hostThrd = pThrd; conn->status = ConnNormal; @@ -1006,8 +1010,8 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int TAOS_CHECK_GOTO(code, NULL, _failed); } - conn->bufSize = BUFFER_LIMIT; - conn->buf = (uv_buf_t*)taosMemoryCalloc(1, BUFFER_LIMIT * sizeof(uv_buf_t)); + conn->bufSize = pInst->shareConnLimit; + conn->buf = (uv_buf_t*)taosMemoryCalloc(1, pInst->shareConnLimit * sizeof(uv_buf_t)); if (conn->buf == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _failed); } @@ -1870,7 +1874,7 @@ static void cliBuildBatch(SCliReq* pReq, queue* h, SCliThrd* pThrd) { return; } - pBatchList->batchLenLimit = pInst->batchSize; + pBatchList->batchLenLimit = pInst->shareConnLimit; SCliBatch* pBatch = NULL; code = createBatch(&pBatch, pBatchList, pReq); @@ -1895,9 +1899,9 @@ static void cliBuildBatch(SCliReq* pReq, queue* h, SCliThrd* pThrd) { } else { queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); SCliBatch* pBatch = QUEUE_DATA(hdr, SCliBatch, listq); - if ((pBatch->batchSize + pReq->msg.contLen) < (*ppBatchList)->batchLenLimit) { + if ((pBatch->shareConnLimit + pReq->msg.contLen) < (*ppBatchList)->batchLenLimit) { QUEUE_PUSH(&pBatch->wq, h); - pBatch->batchSize += pReq->msg.contLen; + pBatch->shareConnLimit += pReq->msg.contLen; pBatch->wLen += 1; } else { SCliBatch* tBatch = NULL; @@ -1962,7 +1966,7 @@ static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliReq* p QUEUE_PUSH(&pBatch->wq, &pReq->q); pBatch->wLen += 1; - pBatch->batchSize = pReq->msg.contLen; + pBatch->shareConnLimit = pReq->msg.contLen; pBatch->pList = pList; QUEUE_PUSH(&pList->wq, &pBatch->listq); @@ -3332,12 +3336,12 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea return code; } -static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentNum, int32_t stateNum) { +static FORCE_INLINE int8_t shouldSWitchToOtherConn(STrans* pInst, int32_t reqNum, int32_t sentNum, int32_t stateNum) { int32_t total = reqNum + sentNum; - if (stateNum >= STATE_BUFFER_LIMIT) { + if (stateNum >= pInst->shareConnLimit) { return 1; } - if (total >= BUFFER_LIMIT) { + if (total >= pInst->shareConnLimit) { return 1; } @@ -3353,11 +3357,13 @@ static FORCE_INLINE bool filterToDebug(void* e, void* arg) { static FORCE_INLINE void logConnMissHit(SCliConn* pConn) { // queue set; // QUEUE_INIT(&set); + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; pConn->heapMissHit++; tDebug("conn %p has %d reqs, %d sentout and %d status in process, total limit:%d, switch to other conn", pConn, transQueueSize(&pConn->reqsToSend), transQueueSize(&pConn->reqsSentOut), taosHashGetSize(pConn->pQTable), - BUFFER_LIMIT); - // if (transQueueSize(&pConn->reqsSentOut) >= BUFFER_LIMIT) { + pInst->shareConnLimit); + // if (transQueueSize(&pConn->reqsSentOut) >= pInst->shareConnLimit) { // transQueueRemoveByFilter(&pConn->reqsSentOut, filterToDebug, NULL, &set, 1); // } } @@ -3376,11 +3382,12 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } else { tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); - int32_t reqsNum = transQueueSize(&pConn->reqsToSend); - int32_t reqsSentOut = transQueueSize(&pConn->reqsSentOut); - int32_t stateNum = taosHashGetSize(pConn->pQTable); - - if (shouldSWitchToOtherConn(reqsNum, reqsSentOut, stateNum)) { + int32_t reqsNum = transQueueSize(&pConn->reqsToSend); + int32_t reqsSentOut = transQueueSize(&pConn->reqsSentOut); + int32_t stateNum = taosHashGetSize(pConn->pQTable); + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + if (shouldSWitchToOtherConn(pInst, reqsNum, reqsSentOut, stateNum)) { logConnMissHit(pConn); return NULL; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 69e4bdd485..9f9ce26e59 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -1293,7 +1293,6 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { TAOS_CHECK_GOTO(code, &lino, _end); } - // memset(&pConn->regArg, 0, sizeof(pConn->regArg)); pConn->broken = false; pConn->status = ConnNormal; @@ -1320,7 +1319,6 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { pConn->refId = exh->refId; QUEUE_INIT(&exh->q); - transRefSrvHandle(pConn); tTrace("%s handle %p, conn %p created, refId:%" PRId64, transLabel(pInst), exh, pConn, pConn->refId); pConn->pQTable = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); @@ -1337,8 +1335,11 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); } - pConn->bufSize = BUFFER_LIMIT; - pConn->buf = taosMemoryCalloc(1, sizeof(uv_buf_t)); + pConn->bufSize = pInst->shareConnLimit; + pConn->buf = taosMemoryCalloc(1, pInst->shareConnLimit * sizeof(uv_buf_t)); + if (pConn->buf == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _end); + } code = uv_tcp_init(pThrd->loop, pConn->pTcp); if (code != 0) { @@ -1351,6 +1352,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { pConn->pInst = pThrd->pInst; pConn->hostThrd = pThrd; + transRefSrvHandle(pConn); return pConn; _end: if (pConn) { diff --git a/source/libs/transport/test/cliBench.c b/source/libs/transport/test/cliBench.c index 134c911401..e73c209d55 100644 --- a/source/libs/transport/test/cliBench.c +++ b/source/libs/transport/test/cliBench.c @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) { rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.connLimitNum = 10; rpcInit.connLimitLock = 1; - rpcInit.batchSize = 16 * 1024; + rpcInit.shareConnLimit = 16 * 1024; rpcInit.supportBatch = 1; rpcDebugFlag = 135; From e7510e8cb3f7ad43e5653603e6e685c2e4607bbe Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 09:13:45 +0800 Subject: [PATCH 152/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 48 +++++++++++++-------------- source/libs/transport/src/transComm.c | 10 +++--- source/libs/transport/src/transSvr.c | 12 +++---- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 9c2ece635f..5081517339 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -615,7 +615,7 @@ void cliHandleResp(SCliConn* conn) { } if (code != 0) { tWarn("%s conn %p recv unexpected packet, msgType:%s, seqNum:%" PRId64 ", qId:%" PRId64 - ", the sever may sends repeated response,reason:%s", + ", the sever may sends repeated response since %s", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), seq, qId, tstrerror(code)); // TODO: notify cb taosMemoryFree(pHead); @@ -1195,7 +1195,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { } cliConnRmReqs(conn); if (status != 0) { - tDebug("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); + tDebug("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(status)); TAOS_UNUSED(transUnrefCliHandle(conn)); return; } @@ -1214,7 +1214,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { if (!cliMayRecycleConn(conn)) { code = cliBatchSend(conn); if (code != 0) { - tDebug("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + tDebug("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); TAOS_UNUSED(transUnrefCliHandle(conn)); } } @@ -1335,7 +1335,7 @@ int32_t cliBatchSend(SCliConn* pConn) { tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); int32_t ret = uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); if (ret != 0) { - tError("%s conn %p failed to send msg, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(ret)); + tError("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(ret)); freeWReqToWQ(&pConn->wq, req->data); code = TSDB_CODE_THIRDPARTY_ERROR; TAOS_UNUSED(transUnrefCliHandle(pConn)); @@ -1387,12 +1387,12 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { int ret = uv_tcp_open((uv_tcp_t*)conn->stream, fd); if (ret != 0) { - tError("%s conn %p failed to set stream, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); + tError("%s conn %p failed to set stream since %s", transLabel(pInst), conn, uv_err_name(ret)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); } ret = transSetConnOption((uv_tcp_t*)conn->stream, 20); if (ret != 0) { - tError("%s conn %p failed to set socket opt, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); + tError("%s conn %p failed to set socket opt since %s", transLabel(pInst), conn, uv_err_name(ret)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); return code; } @@ -1400,7 +1400,7 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { transRefCliHandle(conn); ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { - tError("failed connect to %s, reason:%s", conn->dstAddr, uv_err_name(ret)); + tError("failed connect to %s since %s", conn->dstAddr, uv_err_name(ret)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); } @@ -1408,19 +1408,19 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { transRefCliHandle(conn); ret = uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); if (ret != 0) { - tError("%s conn %p failed to start timer, reason:%s", transLabel(pInst), conn, uv_err_name(ret)); + tError("%s conn %p failed to start timer since %s", transLabel(pInst), conn, uv_err_name(ret)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception2); } return TSDB_CODE_RPC_ASYNC_IN_PROCESS; _exception1: - tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, tstrerror(code)); + tError("%s conn %p failed to do connect since %s", transLabel(pInst), conn, tstrerror(code)); cliDestroyConn(conn, true); return code; _exception2: TAOS_UNUSED(transUnrefCliHandle(conn)); - tError("%s conn %p failed to do connect, reason:%s", transLabel(pInst), conn, tstrerror(code)); + tError("%s conn %p failed to do connect since %s", transLabel(pInst), conn, tstrerror(code)); return code; } @@ -1490,7 +1490,7 @@ void cliConnCb(uv_connect_t* req, int status) { STUB_RAND_NETWORK_ERR(status); if (status != 0) { - tDebug("%s conn %p failed to connect to %s, reason:%s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, + tDebug("%s conn %p failed to connect to %s since %s", CONN_GET_INST_LABEL(pConn), pConn, pConn->dstAddr, uv_strerror(status)); TAOS_UNUSED(transUnrefCliHandle(pConn)); return; @@ -1806,7 +1806,7 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { _exception: resp.code = code; STraceId* trace = &pReq->msg.info.traceId; - tGWarn("%s failed to process req, reason:%s", pInst->label, tstrerror(code)); + tGWarn("%s failed to process req since %s", pInst->label, tstrerror(code)); code = (pThrd->notifyExceptCb)(pThrd, pReq, &resp); if (code != 0) { @@ -1917,7 +1917,7 @@ static void cliBuildBatch(SCliReq* pReq, queue* h, SCliThrd* pThrd) { static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, uint32_t port) { SCliBatchList* pBatchList = taosMemoryCalloc(1, sizeof(SCliBatchList)); if (pBatchList == NULL) { - tError("failed to create batch list, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + tError("failed to create batch list since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); return terrno; } QUEUE_INIT(&pBatchList->wq); @@ -1933,7 +1933,7 @@ static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, taosMemoryFree(pBatchList->ip); taosMemoryFree(pBatchList->dst); taosMemoryFree(pBatchList); - tError("failed to create batch list, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + tError("failed to create batch list since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); return terrno; } *ppBatchList = pBatchList; @@ -1957,7 +1957,7 @@ static void destroyBatchList(SCliBatchList* pList) { static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliReq* pReq) { SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch)); if (pBatch == NULL) { - tError("failed to create batch, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + tError("failed to create batch since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); return terrno; } @@ -1985,13 +1985,13 @@ static void cliAsyncCb(uv_async_t* handle) { // batch process to avoid to lock/unlock frequently queue wq; if (taosThreadMutexLock(&item->mtx) != 0) { - tError("failed to lock mutex, reason:%s", tstrerror(terrno)); + tError("failed to lock mutex since %s", tstrerror(terrno)); } QUEUE_MOVE(&item->qmsg, &wq); if (taosThreadMutexUnlock(&item->mtx) != 0) { - tError("failed to unlock mutex, reason:%s", tstrerror(terrno)); + tError("failed to unlock mutex since %s", tstrerror(terrno)); } cliDealFunc[pInst->supportBatch](&wq, pThrd); @@ -2146,7 +2146,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { code = uv_loop_init(pThrd->loop); if (code != 0) { - tError("failed to init uv_loop, reason:%s", uv_err_name(code)); + tError("failed to init uv_loop since %s", uv_err_name(code)); TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end); } @@ -2264,7 +2264,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { } if (taosThreadJoin(pThrd->thread, NULL) != 0) { - tTrace("failed to join thread, reason:%s", tstrerror(terrno)); + tTrace("failed to join thread since %s", tstrerror(terrno)); } CLI_RELEASE_UV(pThrd->loop); @@ -2591,7 +2591,7 @@ void cliRetryUpdateRule(SReqCtx* pCtx, int8_t noDelay) { int32_t cliRetryDoSched(SCliReq* pReq, SCliThrd* pThrd) { int32_t code = cliSchedMsgToNextNode(pReq, pThrd); if (code != 0) { - tError("failed to sched msg to next node, reason:%s", tstrerror(code)); + tError("failed to sched msg to next node since %s", tstrerror(code)); return code; } return 0; @@ -2657,7 +2657,7 @@ bool cliMayRetry(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { code = cliRetryDoSched(pReq, pThrd); if (code != 0) { pResp->code = code; - tError("failed to sched msg to next node, reason:%s", tstrerror(code)); + tError("failed to sched msg to next node since %s", tstrerror(code)); return false; } return true; @@ -2756,7 +2756,7 @@ void transCloseClient(void* arg) { for (int i = 0; i < cli->numOfThreads; i++) { code = cliSendQuit(cli->pThreadObj[i]); if (code != 0) { - tError("failed to send quit to thread:%d, reason:%s", i, tstrerror(code)); + tError("failed to send quit to thread:%d since %s", i, tstrerror(code)); } destroyThrdObj(cli->pThreadObj[i]); @@ -3317,14 +3317,14 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea SHeap heap = {0}; code = transHeapInit(&heap, compareHeapNode); if (code != 0) { - tError("failed to init heap cache for key:%s, reason: %s", key, tstrerror(code)); + tError("failed to init heap cache for key:%s since %s", key, tstrerror(code)); return code; } code = taosHashPut(pConnHeapCache, key, klen, &heap, sizeof(heap)); if (code != 0) { transHeapDestroy(&heap); - tError("failed to put heap to cache for key:%s, reason: %s", key, tstrerror(code)); + tError("failed to put heap to cache for key:%s since %s", key, tstrerror(code)); return code; } p = taosHashGet(pConnHeapCache, key, klen); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 59be5c4bde..5669202238 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -184,7 +184,7 @@ int32_t transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf) { } } } else { - tError("failed to reset buffer, total:%d, len:%d, reason:%s", p->total, p->len, tstrerror(TSDB_CODE_INVALID_MSG)); + tError("failed to reset buffer, total:%d, len:%d since %s", p->total, p->len, tstrerror(TSDB_CODE_INVALID_MSG)); return TSDB_CODE_INVALID_MSG; } return 0; @@ -281,7 +281,7 @@ int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAs async->data = item; err = uv_async_init(loop, async, cb); if (err != 0) { - tError("failed to init async, reason:%s", uv_err_name(err)); + tError("failed to init async since %s", uv_err_name(err)); code = TSDB_CODE_THIRDPARTY_ERROR; break; } @@ -342,7 +342,7 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { int ret = uv_async_send(async); if (ret != 0) { - tError("failed to send async,reason:%s", uv_err_name(ret)); + tError("failed to send async since %s", uv_err_name(ret)); return TSDB_CODE_THIRDPARTY_ERROR; } return 0; @@ -389,7 +389,7 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) { int32_t code = taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal)); if (code != 0) { - tError("failed to put val to hash, reason:%s", tstrerror(code)); + tError("failed to put val to hash since %s", tstrerror(code)); } iter = taosHashIterate(src->args, iter); } @@ -821,7 +821,7 @@ int32_t transUtilSIpRangeToStr(SIpV4Range* pRange, char* buf) { 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)); + tError("failed to convert ip to string since %s", uv_strerror(err)); return TSDB_CODE_THIRDPARTY_ERROR; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 9f9ce26e59..926fca7425 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -690,8 +690,8 @@ void uvOnSendCb(uv_write_t* req, int status) { SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); STraceId* trace = &smsg->msg.info.traceId; - tGDebug("%s conn %p failed to send, seqNum:%" PRId64 ", qid:%" PRId64 ", reason:%s", transLabel(conn->pInst), - conn, smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); + tGDebug("%s conn %p failed to send, seqNum:%" PRId64 ", qid:%" PRId64 " since %s", transLabel(conn->pInst), conn, + smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); destroySmsg(smsg); } @@ -705,7 +705,7 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) { if (status == 0) { tTrace("success to dispatch conn to work thread"); } else { - tError("fail to dispatch conn to work thread, reason:%s", uv_strerror(status)); + tError("fail to dispatch conn to work thread since %s", uv_strerror(status)); } if (!uv_is_closing((uv_handle_t*)req->data)) { uv_close((uv_handle_t*)req->data, uvFreeCb); @@ -844,7 +844,7 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrRespMsg* smsg) { int32_t ret = uv_write(req, (uv_stream_t*)pConn->pTcp, pBuf, bufNum, uvOnSendCb); if (ret != 0) { - tError("conn %p failed to write data, reason:%s", pConn, uv_err_name(ret)); + tError("conn %p failed to write data since %s", pConn, uv_err_name(ret)); pConn->broken = true; while (!QUEUE_IS_EMPTY(&pWreq->node)) { queue* head = QUEUE_HEAD(&pWreq->node); @@ -1063,7 +1063,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { tError("read error %s", uv_err_name(nread)); } // TODO(log other failure reason) - tWarn("failed to create connect:%p, reason: %s", q, uv_err_name(nread)); + tWarn("failed to create connect:%p since %s", q, uv_err_name(nread)); taosMemoryFree(buf->base); uv_close((uv_handle_t*)q, NULL); return; @@ -1504,7 +1504,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, if (false == taosValidIpAndPort(srv->ip, srv->port)) { code = TAOS_SYSTEM_ERROR(errno); - tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); + tError("invalid ip/port, %d:%d since %s", srv->ip, srv->port, terrstr()); goto End; } char pipeName[PATH_MAX]; From 8276cd5cbef782b525cfd02fb49807368fd7befc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 11:15:39 +0800 Subject: [PATCH 153/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 5081517339..fe3e45ec8c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3437,7 +3437,10 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { SCliConn* args1 = container_of(a, SCliConn, node); SCliConn* args2 = container_of(b, SCliConn, node); - if (transQueueSize(&args1->reqsToSend) > transQueueSize(&args2->reqsToSend)) { + + int32_t totalReq1 = transQueueSize(&args1->reqsToSend) + transQueueSize(&args1->reqsSentOut); + int32_t totalReq2 = transQueueSize(&args2->reqsToSend) + transQueueSize(&args2->reqsSentOut); + if ( totalReq1 > totalReq2) { return 0; } return 1; From 836523bf18c8c177da738d5ce8a88ceeeeb4d9d6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 12:56:55 +0800 Subject: [PATCH 154/240] add user req --- source/libs/transport/inc/transComm.h | 21 +++- source/libs/transport/src/transCli.c | 163 ++++++++++++++++++-------- source/libs/transport/src/transComm.c | 46 +++++++- 3 files changed, 170 insertions(+), 60 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 8b7311fe3b..d20b992315 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -137,10 +137,19 @@ typedef struct SCvtAddr { } SCvtAddr; typedef struct { - SEpSet epSet; // ip list provided by app - SEpSet origEpSet; - void* ahandle; // handle provided by app - tmsg_t msgType; // message type + int32_t inUse; + int32_t numOfEps; + SEp eps[]; +} SReqEpSet; + +int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqEpSet); +int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEpSet); + +typedef struct { + SReqEpSet* epSet; // ip list provided by app + SReqEpSet* origEpSet; + void* ahandle; // handle provided by app + tmsg_t msgType; // message type STransCtx userCtx; // STransMsg* pRsp; // for synchronous API @@ -438,9 +447,9 @@ 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); -bool transEpSetIsEqual(SEpSet* a, SEpSet* b); +bool transRepEpsetIsEqual(SReqEpSet* a, SReqEpSet* b); -bool transEpSetIsEqual2(SEpSet* a, SEpSet* b); +bool transCompareReqAndUserEpset(SReqEpSet* a, SEpSet* b); /* * init global func */ diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index fe3e45ec8c..3b40b3931f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -230,7 +230,7 @@ static void doFreeTimeoutMsg(void* param); static void cliDestroyBatch(SCliBatch* pBatch); // cli util func static FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx); -static FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr); +static FORCE_INLINE int32_t cliMayCvtFqdnToIp(SReqEpSet* pEpSet, const SCvtAddr* pCvtAddr); static FORCE_INLINE int32_t cliBuildExceptResp(SCliThrd* thrd, SCliReq* pReq, STransMsg* resp); @@ -831,8 +831,8 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p // code static int32_t cliGetOrCreateConn(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { // impl later - char* fqdn = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); - uint16_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); + char* fqdn = EPSET_GET_INUSE_IP(pReq->ctx->epSet); + uint16_t port = EPSET_GET_INUSE_PORT(pReq->ctx->epSet); char addr[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(addr, fqdn, port); @@ -932,8 +932,8 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) { int32_t code = 0; SCliConn* pConn = NULL; - char* ip = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); - int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); + char* ip = EPSET_GET_INUSE_IP(pReq->ctx->epSet); + int32_t port = EPSET_GET_INUSE_PORT(pReq->ctx->epSet); TAOS_CHECK_GOTO(cliCreateConn(pThrd, &pConn, ip, port), NULL, _exception); @@ -1559,7 +1559,7 @@ static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { return; } -FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr) { +FORCE_INLINE int32_t cliMayCvtFqdnToIp(SReqEpSet* pEpSet, const SCvtAddr* pCvtAddr) { if (pCvtAddr == NULL) { return 0; } @@ -1583,7 +1583,7 @@ FORCE_INLINE int32_t cliMayCvtFqdnToIp(SEpSet* pEpSet, const SCvtAddr* pCvtAddr) FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx) { if (code != 0) return false; - return transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet) ? false : true; + return transRepEpsetIsEqual(pCtx->epSet, pCtx->origEpSet) ? false : true; } FORCE_INLINE int32_t cliBuildExceptResp(SCliThrd* pThrd, SCliReq* pReq, STransMsg* pResp) { @@ -1770,8 +1770,8 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { if (code == TSDB_CODE_RPC_NO_STATE || code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { char addr[TSDB_FQDN_LEN + 64] = {0}; - char* ip = EPSET_GET_INUSE_IP(&pReq->ctx->epSet); - int32_t port = EPSET_GET_INUSE_PORT(&pReq->ctx->epSet); + char* ip = EPSET_GET_INUSE_IP(pReq->ctx->epSet); + int32_t port = EPSET_GET_INUSE_PORT(pReq->ctx->epSet); CONN_CONSTRUCT_HASH_KEY(addr, ip, port); pConn = getConnFromHeapCache(pThrd->connHeapCache, addr); @@ -1860,8 +1860,8 @@ static void cliBuildBatch(SCliReq* pReq, queue* h, SCliThrd* pThrd) { STrans* pInst = pThrd->pInst; SReqCtx* pCtx = pReq->ctx; - char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet); - uint32_t port = EPSET_GET_INUSE_PORT(&pCtx->epSet); + char* ip = EPSET_GET_INUSE_IP(pCtx->epSet); + uint32_t port = EPSET_GET_INUSE_PORT(pCtx->epSet); char key[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(key, ip, port); size_t klen = strlen(key); @@ -2007,7 +2007,9 @@ static FORCE_INLINE void destroyReq(void* arg) { STraceId* trace = &pReq->msg.info.traceId; tGDebug("free memory:%p, free ctx: %p", pReq, pReq->ctx); - if (pReq->ctx) destroyReqCtx(pReq->ctx); + if (pReq->ctx) { + destroyReqCtx(pReq->ctx); + } transFreeMsg(pReq->msg.pCont); taosMemoryFree(pReq); } @@ -2102,7 +2104,7 @@ int32_t initCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { if (pReq->ctx == NULL) { return 0; } - return cliMayCvtFqdnToIp(&pReq->ctx->epSet, pThrd->pCvtAddr); + return cliMayCvtFqdnToIp(pReq->ctx->epSet, pThrd->pCvtAddr); } int32_t notifyExceptCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = thrd; @@ -2319,7 +2321,13 @@ static void destroyThrdObj(SCliThrd* pThrd) { taosMemoryFree(pThrd); } -static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx) { taosMemoryFree(ctx); } +static FORCE_INLINE void destroyReqCtx(SReqCtx* ctx) { + if (ctx) { + taosMemoryFree(ctx->epSet); + taosMemoryFree(ctx->origEpSet); + taosMemoryFree(ctx); + } +} int32_t cliSendQuit(SCliThrd* thrd) { // cli can stop gracefully @@ -2391,7 +2399,7 @@ static FORCE_INLINE void cliPerfLog_schedMsg(SCliReq* pReq, char* label) { STraceId* trace = &pReq->msg.info.traceId; char tbuf[512] = {0}; - code = epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + code = epsetToStr((SEpSet*)pCtx->epSet, tbuf, tListLen(tbuf)); if (code != 0) { tWarn("failed to debug epset since %s", tstrerror(code)); return; @@ -2410,7 +2418,7 @@ static FORCE_INLINE void cliPerfLog_epset(SCliConn* pConn, SCliReq* pReq) { char tbuf[512] = {0}; - code = epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + code = epsetToStr((SEpSet*)pCtx->epSet, tbuf, tListLen(tbuf)); if (code != 0) { tWarn("failed to debug epset since %s", tstrerror(code)); return; @@ -2442,7 +2450,6 @@ static FORCE_INLINE int32_t cliSchedMsgToNextNode(SCliReq* pReq, SCliThrd* pThrd FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { int32_t code = 0; SReqCtx* ctx = pReq->ctx; - SEpSet* dst = &ctx->epSet; if ((pResp == NULL || pResp->info.hasEpSet == 0)) { return false; @@ -2453,7 +2460,8 @@ FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { tError("failed to deserialize epset, code:%d", code); return false; } - int32_t tlen = tSerializeSEpSet(NULL, 0, dst); + SEpSet tepset; + int32_t tlen = tSerializeSEpSet(NULL, 0, &tepset); char* buf = NULL; int32_t len = pResp->contLen - tlen; @@ -2473,7 +2481,7 @@ FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { pResp->info.hasEpSet = 1; - epsetAssign(dst, &epset); + transCreateReqEpsetFromUserEpset(&epset, &ctx->epSet); return true; } @@ -2481,34 +2489,35 @@ bool cliResetEpset(SReqCtx* pCtx, STransMsg* pResp, bool hasEpSet) { bool noDelay = true; if (hasEpSet == false) { if (pResp->contLen == 0) { - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } else if (pResp->contLen != 0) { SEpSet epSet; int32_t valid = tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epSet); if (valid < 0) { tDebug("get invalid epset, epset equal, continue"); - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } else { - if (!transEpSetIsEqual2(&pCtx->epSet, &epSet)) { + if (!transCompareReqAndUserEpset(pCtx->epSet, &epSet)) { tDebug("epset not equal, retry new epset1"); - transPrintEpSet(&pCtx->epSet); + transPrintEpSet((SEpSet*)pCtx->epSet); transPrintEpSet(&epSet); - epsetAssign(&pCtx->epSet, &epSet); + + transCreateReqEpsetFromUserEpset(&epSet, &pCtx->epSet); noDelay = false; } else { - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { tDebug("epset equal, continue"); - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } } @@ -2518,24 +2527,24 @@ bool cliResetEpset(SReqCtx* pCtx, STransMsg* pResp, bool hasEpSet) { int32_t valid = tDeserializeSEpSet(pResp->pCont, pResp->contLen, &epSet); if (valid < 0) { tDebug("get invalid epset, epset equal, continue"); - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } else { - if (!transEpSetIsEqual2(&pCtx->epSet, &epSet)) { + if (!transCompareReqAndUserEpset(pCtx->epSet, &epSet)) { tDebug("epset not equal, retry new epset2"); - transPrintEpSet(&pCtx->epSet); + transPrintEpSet((SEpSet*)pCtx->epSet); transPrintEpSet(&epSet); - epsetAssign(&pCtx->epSet, &epSet); + transCreateReqEpsetFromUserEpset(&epSet, &pCtx->epSet); noDelay = false; } else { - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { noDelay = false; } else { tDebug("epset equal, continue"); - EPSET_FORWARD_INUSE(&pCtx->epSet); + EPSET_FORWARD_INUSE(pCtx->epSet); } } } @@ -2675,7 +2684,7 @@ void cliMayResetRespCode(SCliReq* pReq, STransMsg* pResp) { } // check whole vnodes is offline on this vgroup - if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps || pCtx->retryStep > 0) { + if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps || pCtx->retryStep > 0) { if (pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { pResp->code = TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED; } else if (pResp->code == TSDB_CODE_RPC_BROKEN_LINK) { @@ -2710,7 +2719,10 @@ int32_t cliNotifyImplCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { memcpy(pSyncMsg->pRsp, (char*)pResp, sizeof(*pResp)); if (cliIsEpsetUpdated(pResp->code, pCtx)) { pSyncMsg->hasEpSet = 1; - epsetAssign(&pSyncMsg->epSet, &pCtx->epSet); + + SEpSet epset = {0}; + transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset); + epsetAssign(&pSyncMsg->epSet, &epset); } TAOS_UNUSED(tsem2_post(pSyncMsg->pSem)); TAOS_UNUSED(taosReleaseRef(transGetSyncMsgMgt(), pCtx->syncMsgRef)); @@ -2721,12 +2733,16 @@ int32_t cliNotifyImplCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { } else { tGTrace("%s conn %p handle resp", CONN_GET_INST_LABEL(pConn), pConn); if (pResp->info.hasEpSet == 1) { - pInst->cfp(pInst->parent, pResp, &pCtx->epSet); + SEpSet epset = {0}; + transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset); + pInst->cfp(pInst->parent, pResp, &epset); } else { if (!cliIsEpsetUpdated(pResp->code, pCtx)) { pInst->cfp(pInst->parent, pResp, NULL); } else { - pInst->cfp(pInst->parent, pResp, &pCtx->epSet); + SEpSet epset = {0}; + transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset); + pInst->cfp(pInst->parent, pResp, &epset); } } } @@ -2862,6 +2878,7 @@ int32_t transReleaseCliHandle(void* handle) { } static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx, SCliReq** pCliMsg) { + int32_t code = 0; TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); @@ -2869,8 +2886,18 @@ static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pRe return terrno; } - epsetAssign(&pCtx->epSet, pEpSet); - epsetAssign(&pCtx->origEpSet, pEpSet); + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->epSet); + if (code != 0) { + taosMemoryFree(pCtx); + return code; + } + + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->origEpSet); + if (code != 0) { + taosMemoryFree(pCtx); + taosMemoryFree(pCtx->epSet); + return code; + } pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; @@ -2983,7 +3010,9 @@ int32_t transSendRecv(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STr pReq->pCont = NULL; return TSDB_CODE_RPC_MODULE_QUIT; } - int32_t code = 0; + int32_t code = 0; + SCliReq* pCliReq = NULL; + SReqCtx* pCtx = NULL; STransMsg* pTransRsp = taosMemoryCalloc(1, sizeof(STransMsg)); if (pTransRsp == NULL) { @@ -3008,25 +3037,36 @@ int32_t transSendRecv(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STr if (pReq->info.traceId.msgId == 0) TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); - SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); + pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { TAOS_UNUSED(tsem_destroy(sem)); taosMemoryFree(sem); TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } - epsetAssign(&pCtx->epSet, pEpSet); - epsetAssign(&pCtx->origEpSet, pEpSet); + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->epSet); + if (code != 0) { + (TAOS_UNUSED(tsem_destroy(sem))); + taosMemoryFree(sem); + TAOS_CHECK_GOTO(code, NULL, _RETURN1); + } + + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->origEpSet); + if (code != 0) { + (TAOS_UNUSED(tsem_destroy(sem))); + taosMemoryFree(sem); + TAOS_CHECK_GOTO(code, NULL, _RETURN1); + } + pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; pCtx->pSem = sem; pCtx->pRsp = pTransRsp; - SCliReq* pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); + pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); if (pCliReq == NULL) { (TAOS_UNUSED(tsem_destroy(sem))); taosMemoryFree(sem); - taosMemoryFree(pCtx); TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } @@ -3037,7 +3077,7 @@ int32_t transSendRecv(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STr STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, - EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); + EPSET_GET_INUSE_IP(pCtx->epSet), EPSET_GET_INUSE_PORT(pCtx->epSet), pReq->info.ahandle); code = transAsyncSend(pThrd->asyncPool, &pCliReq->q); if (code != 0) { @@ -3059,6 +3099,11 @@ _RETURN1: taosMemoryFree(pTransRsp); taosMemoryFree(pReq->pCont); pReq->pCont = NULL; + if (pCtx != NULL) { + taosMemoryFree(pCtx->epSet); + taosMemoryFree(pCtx->origEpSet); + taosMemoryFree(pCtx); + } return code; } @@ -3126,8 +3171,16 @@ int32_t transSendRecvWithTimeout(void* pInstRef, SEpSet* pEpSet, STransMsg* pReq TAOS_CHECK_GOTO(terrno, NULL, _RETURN2); } - epsetAssign(&pCtx->epSet, pEpSet); - epsetAssign(&pCtx->origEpSet, pEpSet); + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->epSet); + if (code != 0) { + taosMemoryFreeClear(pCtx->epSet); + TAOS_CHECK_GOTO(code, NULL, _RETURN2); + } + code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->origEpSet); + if (code != 0) { + taosMemoryFreeClear(pCtx->epSet); + TAOS_CHECK_GOTO(code, NULL, _RETURN2); + } pCtx->ahandle = pReq->info.ahandle; pCtx->msgType = pReq->msgType; @@ -3156,7 +3209,7 @@ int32_t transSendRecvWithTimeout(void* pInstRef, SEpSet* pEpSet, STransMsg* pReq STraceId* trace = &pReq->info.traceId; tGDebug("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pInst), pThrd->pid, - EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); + EPSET_GET_INUSE_IP(pCtx->epSet), EPSET_GET_INUSE_PORT(pCtx->epSet), pReq->info.ahandle); code = transAsyncSend(pThrd->asyncPool, &pCliReq->q); if (code != 0) { @@ -3183,6 +3236,12 @@ _RETURN: return code; _RETURN2: transFreeMsg(pReq->pCont); + + if (pCtx != NULL) { + taosMemoryFree(pCtx->epSet); + taosMemoryFree(pCtx->origEpSet); + taosMemoryFree(pCtx); + } pReq->pCont = NULL; taosMemoryFree(pTransMsg); transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); @@ -3440,7 +3499,7 @@ int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { int32_t totalReq1 = transQueueSize(&args1->reqsToSend) + transQueueSize(&args1->reqsSentOut); int32_t totalReq2 = transQueueSize(&args2->reqsToSend) + transQueueSize(&args2->reqsSentOut); - if ( totalReq1 > totalReq2) { + if (totalReq1 > totalReq2) { return 0; } return 1; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 5669202238..7466cd9fbc 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -667,7 +667,7 @@ void transPrintEpSet(SEpSet* pEpSet) { len += snprintf(buf + len, sizeof(buf) - len, "}"); tTrace("%s, inUse:%d", buf, pEpSet->inUse); } -bool transEpSetIsEqual(SEpSet* a, SEpSet* b) { +bool transRepEpsetIsEqual(SReqEpSet* a, SReqEpSet* b) { if (a->numOfEps != b->numOfEps || a->inUse != b->inUse) { return false; } @@ -678,7 +678,7 @@ bool transEpSetIsEqual(SEpSet* a, SEpSet* b) { } return true; } -bool transEpSetIsEqual2(SEpSet* a, SEpSet* b) { +bool transCompareReqAndUserEpset(SReqEpSet* a, SEpSet* b) { if (a->numOfEps != b->numOfEps) { return false; } @@ -934,4 +934,46 @@ int32_t transSetReadOption(uv_handle_t* handle) { } code = taosSetSockOpt2(fd); return code; +} + +int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqEpSet) { + if (pEpset == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + if (pReqEpSet == NULL) { + return TSDB_CODE_INVALID_PARA; + } + taosMemoryFree(*pReqEpSet); + + int32_t size = sizeof(SReqEpSet) + sizeof(SEp) * pEpset->numOfEps; + SReqEpSet* pReq = (SReqEpSet*)taosMemoryCalloc(1, size); + if (pReq == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pReq->inUse = pEpset->inUse; + pReq->numOfEps = pEpset->numOfEps; + for (int32_t i = 0; i < pEpset->numOfEps; i++) { + pReq->eps[i].port = pEpset->eps[i].port; + strcpy(pReq->eps[i].fqdn, pEpset->eps[i].fqdn); + } + + *pReqEpSet = pReq; + return TSDB_CODE_SUCCESS; +} + +int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEpSet) { + if (pReqEpSet == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + pEpSet->inUse = pReqEpSet->inUse; + pEpSet->numOfEps = pReqEpSet->numOfEps; + for (int32_t i = 0; i < pReqEpSet->numOfEps; i++) { + pEpSet->eps[i].port = pReqEpSet->eps[i].port; + strcpy(pEpSet->eps[i].fqdn, pReqEpSet->eps[i].fqdn); + } + + return TSDB_CODE_SUCCESS; } \ No newline at end of file From 108139ffad37c151ea872555f65bc807b66e0ce9 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 13:13:51 +0800 Subject: [PATCH 155/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3b40b3931f..f899896410 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2881,22 +2881,20 @@ static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pRe int32_t code = 0; TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64()); + SCliReq* pCliReq = NULL; SReqCtx* pCtx = taosMemoryCalloc(1, sizeof(SReqCtx)); if (pCtx == NULL) { - return terrno; + TAOS_CHECK_GOTO(terrno, NULL, _exception); } code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->epSet); if (code != 0) { - taosMemoryFree(pCtx); - return code; + TAOS_CHECK_GOTO(code, NULL, _exception); } code = transCreateReqEpsetFromUserEpset(pEpSet, &pCtx->origEpSet); if (code != 0) { - taosMemoryFree(pCtx); - taosMemoryFree(pCtx->epSet); - return code; + TAOS_CHECK_GOTO(code, NULL, _exception); } pCtx->ahandle = pReq->info.ahandle; @@ -2904,10 +2902,9 @@ static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pRe if (ctx != NULL) pCtx->userCtx = *ctx; - SCliReq* pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); + pCliReq = taosMemoryCalloc(1, sizeof(SCliReq)); if (pReq == NULL) { - taosMemoryFree(pCtx); - return terrno; + TAOS_CHECK_GOTO(terrno, NULL, _exception); } pCliReq->ctx = pCtx; @@ -2916,8 +2913,15 @@ static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pRe pCliReq->type = Normal; *pCliMsg = pCliReq; - - return 0; + return code; +_exception: + if (pCtx == NULL) { + taosMemoryFree(pCtx->epSet); + taosMemoryFree(pCtx->origEpSet); + taosMemoryFree(pCtx); + } + taosMemoryFree(pCliReq); + return code; } int32_t transSendRequest(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, STransCtx* ctx) { From 2947aaf89a2c46ac097a9b6a1c55ad4bf4a9b9cb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 13:27:52 +0800 Subject: [PATCH 156/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transComm.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 7466cd9fbc..b78df9f5ba 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -951,14 +951,7 @@ int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqE if (pReq == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - - pReq->inUse = pEpset->inUse; - pReq->numOfEps = pEpset->numOfEps; - for (int32_t i = 0; i < pEpset->numOfEps; i++) { - pReq->eps[i].port = pEpset->eps[i].port; - strcpy(pReq->eps[i].fqdn, pEpset->eps[i].fqdn); - } - + memcpy((char*)pReqEpSet, (char*)pEpset, size); *pReqEpSet = pReq; return TSDB_CODE_SUCCESS; } @@ -967,13 +960,6 @@ int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEp if (pReqEpSet == NULL) { return TSDB_CODE_INVALID_PARA; } - - pEpSet->inUse = pReqEpSet->inUse; - pEpSet->numOfEps = pReqEpSet->numOfEps; - for (int32_t i = 0; i < pReqEpSet->numOfEps; i++) { - pEpSet->eps[i].port = pReqEpSet->eps[i].port; - strcpy(pEpSet->eps[i].fqdn, pReqEpSet->eps[i].fqdn); - } - + memcpy((char*)pEpSet, (char*)pReqEpSet, sizeof(SReqEpSet) + sizeof(SEp) * pReqEpSet->numOfEps); return TSDB_CODE_SUCCESS; } \ No newline at end of file From fb059dbdd07e93da2eb932e55ca2280a264eb057 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 13:40:27 +0800 Subject: [PATCH 157/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- include/common/tmsg.h | 10 ++++++++-- source/libs/transport/inc/transComm.h | 6 ------ source/libs/transport/src/transComm.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index bc61e21d16..2a61d34ef4 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -971,6 +971,12 @@ typedef struct SEpSet { SEp eps[TSDB_MAX_REPLICA]; } SEpSet; +typedef struct { + int8_t inUse; + int8_t numOfEps; + SEp eps[]; +} SReqEpSet; + int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp); int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp); int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp); @@ -2822,8 +2828,8 @@ enum { TOPIC_SUB_TYPE__COLUMN, }; -#define DEFAULT_MAX_POLL_INTERVAL 300000 -#define DEFAULT_SESSION_TIMEOUT 12000 +#define DEFAULT_MAX_POLL_INTERVAL 300000 +#define DEFAULT_SESSION_TIMEOUT 12000 typedef struct { char name[TSDB_TOPIC_FNAME_LEN]; // accout.topic diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index d20b992315..7481c44daf 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -136,12 +136,6 @@ typedef struct SCvtAddr { bool cvt; } SCvtAddr; -typedef struct { - int32_t inUse; - int32_t numOfEps; - SEp eps[]; -} SReqEpSet; - int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqEpSet); int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEpSet); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index b78df9f5ba..bba1e41683 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -951,7 +951,7 @@ int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqE if (pReq == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - memcpy((char*)pReqEpSet, (char*)pEpset, size); + memcpy((char*)pReq, (char*)pEpset, size); *pReqEpSet = pReq; return TSDB_CODE_SUCCESS; } From 10884dd534ca9b440ea52ac7cf9697a50d86d56e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 13:52:24 +0800 Subject: [PATCH 158/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- include/common/tmsg.h | 5 --- source/libs/transport/inc/transComm.h | 59 +++++++++++++++------------ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 2a61d34ef4..b9a2eed7a1 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -971,11 +971,6 @@ typedef struct SEpSet { SEp eps[TSDB_MAX_REPLICA]; } SEpSet; -typedef struct { - int8_t inUse; - int8_t numOfEps; - SEp eps[]; -} SReqEpSet; int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp); int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp); diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 7481c44daf..93f948f7ed 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -136,35 +136,13 @@ typedef struct SCvtAddr { bool cvt; } SCvtAddr; -int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqEpSet); -int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEpSet); +#pragma pack(push, 1) typedef struct { - SReqEpSet* epSet; // ip list provided by app - SReqEpSet* origEpSet; - void* ahandle; // handle provided by app - tmsg_t msgType; // message type - - STransCtx userCtx; // - STransMsg* pRsp; // for synchronous API - tsem_t* pSem; // for synchronous API - STransSyncMsg* pSyncMsg; // for syncchronous with timeout API - int64_t syncMsgRef; - SCvtAddr* pCvtAddr; - - int64_t retryInitTimestamp; - int64_t retryNextInterval; - int64_t retryMaxTimeout; - int32_t retryMinInterval; - int32_t retryMaxInterval; - int32_t retryStepFactor; - int32_t retryStep; - int32_t retryCode; - int8_t retryInit; - int8_t epsetRetryCnt; -} SReqCtx; - -#pragma pack(push, 1) + int8_t inUse; + int8_t numOfEps; + SEp eps[]; +} SReqEpSet; #define TRANS_VER 2 typedef struct { @@ -205,6 +183,33 @@ typedef struct { #pragma pack(pop) +int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqEpSet); +int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEpSet); + +typedef struct { + SReqEpSet* epSet; // ip list provided by app + SReqEpSet* origEpSet; + void* ahandle; // handle provided by app + tmsg_t msgType; // message type + + STransCtx userCtx; // + STransMsg* pRsp; // for synchronous API + tsem_t* pSem; // for synchronous API + STransSyncMsg* pSyncMsg; // for syncchronous with timeout API + int64_t syncMsgRef; + SCvtAddr* pCvtAddr; + + int64_t retryInitTimestamp; + int64_t retryNextInterval; + int64_t retryMaxTimeout; + int32_t retryMinInterval; + int32_t retryMaxInterval; + int32_t retryStepFactor; + int32_t retryStep; + int32_t retryCode; + int8_t retryInit; + int8_t epsetRetryCnt; +} SReqCtx; typedef enum { Normal, Quit, Release, Register, Update, FreeById } STransMsgType; typedef enum { ConnNormal, ConnAcquire, ConnRelease, ConnBroken, ConnInPool } ConnStatus; From 545a9d74e96d8511ac40602bfd3e26d926d611f2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 14:16:00 +0800 Subject: [PATCH 159/240] add user req --- source/libs/transport/src/transCli.c | 24 ++++++++++++++++++------ source/libs/transport/src/transComm.c | 3 ++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f899896410..4117ffc924 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2481,7 +2481,9 @@ FORCE_INLINE bool cliTryUpdateEpset(SCliReq* pReq, STransMsg* pResp) { pResp->info.hasEpSet = 1; - transCreateReqEpsetFromUserEpset(&epset, &ctx->epSet); + if (transCreateReqEpsetFromUserEpset(&epset, &ctx->epSet) != 0) { + return false; + } return true; } @@ -2510,7 +2512,9 @@ bool cliResetEpset(SReqCtx* pCtx, STransMsg* pResp, bool hasEpSet) { transPrintEpSet((SEpSet*)pCtx->epSet); transPrintEpSet(&epSet); - transCreateReqEpsetFromUserEpset(&epSet, &pCtx->epSet); + if (transCreateReqEpsetFromUserEpset(&epSet, &pCtx->epSet) != 0) { + tDebug("failed to create req epset from user epset"); + } noDelay = false; } else { if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { @@ -2537,7 +2541,9 @@ bool cliResetEpset(SReqCtx* pCtx, STransMsg* pResp, bool hasEpSet) { tDebug("epset not equal, retry new epset2"); transPrintEpSet((SEpSet*)pCtx->epSet); transPrintEpSet(&epSet); - transCreateReqEpsetFromUserEpset(&epSet, &pCtx->epSet); + if (transCreateReqEpsetFromUserEpset(&epSet, &pCtx->epSet) != 0) { + tError("failed to create req epset from user epset"); + } noDelay = false; } else { if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) { @@ -2721,7 +2727,9 @@ int32_t cliNotifyImplCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { pSyncMsg->hasEpSet = 1; SEpSet epset = {0}; - transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset); + if (transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset) != 0) { + tError("failed to create user epset from req epset"); + } epsetAssign(&pSyncMsg->epSet, &epset); } TAOS_UNUSED(tsem2_post(pSyncMsg->pSem)); @@ -2734,14 +2742,18 @@ int32_t cliNotifyImplCb(SCliConn* pConn, SCliReq* pReq, STransMsg* pResp) { tGTrace("%s conn %p handle resp", CONN_GET_INST_LABEL(pConn), pConn); if (pResp->info.hasEpSet == 1) { SEpSet epset = {0}; - transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset); + if (transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset) != 0) { + tError("failed to create user epset from req epset"); + } pInst->cfp(pInst->parent, pResp, &epset); } else { if (!cliIsEpsetUpdated(pResp->code, pCtx)) { pInst->cfp(pInst->parent, pResp, NULL); } else { SEpSet epset = {0}; - transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset); + if (transCreateUserEpsetFromReqEpset(pCtx->epSet, &epset) != 0) { + tError("failed to create user epset from req epset"); + } pInst->cfp(pInst->parent, pResp, &epset); } } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index bba1e41683..3c42a1ec83 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -944,7 +944,6 @@ int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqE if (pReqEpSet == NULL) { return TSDB_CODE_INVALID_PARA; } - taosMemoryFree(*pReqEpSet); int32_t size = sizeof(SReqEpSet) + sizeof(SEp) * pEpset->numOfEps; SReqEpSet* pReq = (SReqEpSet*)taosMemoryCalloc(1, size); @@ -952,6 +951,8 @@ int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqE return TSDB_CODE_OUT_OF_MEMORY; } memcpy((char*)pReq, (char*)pEpset, size); + + taosMemoryFree(*pReqEpSet); *pReqEpSet = pReq; return TSDB_CODE_SUCCESS; } From f40f417bd2dd202cb98cca81047aac502891f326 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 14:32:59 +0800 Subject: [PATCH 160/240] add user req --- source/libs/transport/src/transCli.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4117ffc924..26f39149db 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1332,7 +1332,14 @@ int32_t cliBatchSend(SCliConn* pConn) { } transRefCliHandle(pConn); uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); + if (req == NULL) { + tError("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(terrno)); + transRefCliHandle(pConn); + return terrno; + } + tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); + int32_t ret = uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); if (ret != 0) { tError("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(ret)); @@ -1340,6 +1347,7 @@ int32_t cliBatchSend(SCliConn* pConn) { code = TSDB_CODE_THIRDPARTY_ERROR; TAOS_UNUSED(transUnrefCliHandle(pConn)); } + return code; } From b15506c1de4ca59df1a864a19fcd7c5e5eecbbfc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 15:09:30 +0800 Subject: [PATCH 161/240] add user req --- source/libs/transport/src/transCli.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 26f39149db..2b5906396a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1568,7 +1568,7 @@ static void cliHandleUpdate(SCliThrd* pThrd, SCliReq* pReq) { } FORCE_INLINE int32_t cliMayCvtFqdnToIp(SReqEpSet* pEpSet, const SCvtAddr* pCvtAddr) { - if (pCvtAddr == NULL) { + if (pEpSet == NULL || pCvtAddr == NULL) { return 0; } if (pCvtAddr->cvt == false) { @@ -1578,6 +1578,7 @@ FORCE_INLINE int32_t cliMayCvtFqdnToIp(SReqEpSet* pEpSet, const SCvtAddr* pCvtAd return TSDB_CODE_RPC_FQDN_ERROR; } } + if (pEpSet->numOfEps == 1 && strncmp(pEpSet->eps[0].fqdn, pCvtAddr->fqdn, TSDB_FQDN_LEN) == 0) { memset(pEpSet->eps[0].fqdn, 0, TSDB_FQDN_LEN); memcpy(pEpSet->eps[0].fqdn, pCvtAddr->ip, TSDB_FQDN_LEN); From ee5794f4941e6d2f0e2990a4dd0cb17e7946491a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 15:19:18 +0800 Subject: [PATCH 162/240] add user req --- source/libs/transport/inc/transComm.h | 2 +- source/libs/transport/src/transCli.c | 2 +- source/libs/transport/src/transComm.c | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 93f948f7ed..fa5cc2a09d 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -446,7 +446,7 @@ 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); -bool transRepEpsetIsEqual(SReqEpSet* a, SReqEpSet* b); +bool transReqEpsetIsEqual(SReqEpSet* a, SReqEpSet* b); bool transCompareReqAndUserEpset(SReqEpSet* a, SEpSet* b); /* diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 2b5906396a..bb54f9e2cb 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1592,7 +1592,7 @@ FORCE_INLINE int32_t cliMayCvtFqdnToIp(SReqEpSet* pEpSet, const SCvtAddr* pCvtAd FORCE_INLINE bool cliIsEpsetUpdated(int32_t code, SReqCtx* pCtx) { if (code != 0) return false; - return transRepEpsetIsEqual(pCtx->epSet, pCtx->origEpSet) ? false : true; + return transReqEpsetIsEqual(pCtx->epSet, pCtx->origEpSet) ? false : true; } FORCE_INLINE int32_t cliBuildExceptResp(SCliThrd* pThrd, SCliReq* pReq, STransMsg* pResp) { diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 3c42a1ec83..453cb43ed3 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -667,7 +667,13 @@ void transPrintEpSet(SEpSet* pEpSet) { len += snprintf(buf + len, sizeof(buf) - len, "}"); tTrace("%s, inUse:%d", buf, pEpSet->inUse); } -bool transRepEpsetIsEqual(SReqEpSet* a, SReqEpSet* b) { +bool transReqEpsetIsEqual(SReqEpSet* a, SReqEpSet* b) { + if (a == NULL && b == NULL) { + return true; + } else if (a == NULL || b == NULL) { + return false; + } + if (a->numOfEps != b->numOfEps || a->inUse != b->inUse) { return false; } From 74b6e98b764739004e9f776a834eb5d950246b1d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 19:08:37 +0800 Subject: [PATCH 163/240] add pre check --- source/libs/transport/inc/transComm.h | 2 ++ source/libs/transport/src/transCli.c | 7 ++++++- source/libs/transport/src/transComm.c | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index fa5cc2a09d..42ee0894d0 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -186,6 +186,8 @@ typedef struct { int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqEpSet); int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEpSet); +int32_t transValidReqEpset(SReqEpSet* pReqEpSet); + typedef struct { SReqEpSet* epSet; // ip list provided by app SReqEpSet* origEpSet; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index bb54f9e2cb..75f1a6db05 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2936,7 +2936,7 @@ static int32_t transInitMsg(void* pInstRef, const SEpSet* pEpSet, STransMsg* pRe *pCliMsg = pCliReq; return code; _exception: - if (pCtx == NULL) { + if (pCtx != NULL) { taosMemoryFree(pCtx->epSet); taosMemoryFree(pCtx->origEpSet); taosMemoryFree(pCtx); @@ -2979,6 +2979,9 @@ _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + if (code != 0) { + tError("failed to send request since %s", tstrerror(code)); + } return code; } int32_t transSendRequestWithId(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { @@ -3025,6 +3028,8 @@ _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); + + tError("failed to send request since %s", tstrerror(code)); return code; } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 453cb43ed3..a149a32d96 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -957,8 +957,14 @@ int32_t transCreateReqEpsetFromUserEpset(const SEpSet* pEpset, SReqEpSet** pReqE return TSDB_CODE_OUT_OF_MEMORY; } memcpy((char*)pReq, (char*)pEpset, size); - + // clear previous taosMemoryFree(*pReqEpSet); + + if (transValidReqEpset(pReq) != TSDB_CODE_SUCCESS) { + taosMemoryFree(pReq); + return TSDB_CODE_INVALID_PARA; + } + *pReqEpSet = pReq; return TSDB_CODE_SUCCESS; } @@ -969,4 +975,14 @@ int32_t transCreateUserEpsetFromReqEpset(const SReqEpSet* pReqEpSet, SEpSet* pEp } memcpy((char*)pEpSet, (char*)pReqEpSet, sizeof(SReqEpSet) + sizeof(SEp) * pReqEpSet->numOfEps); return TSDB_CODE_SUCCESS; +} + +int32_t transValidReqEpset(SReqEpSet* pReqEpSet) { + if (pReqEpSet == NULL) { + return TSDB_CODE_INVALID_PARA; + } + if (pReqEpSet->numOfEps == 0 || pReqEpSet->numOfEps > TSDB_MAX_EP_NUM || pReqEpSet->inUse >= TSDB_MAX_EP_NUM) { + return TSDB_CODE_INVALID_PARA; + } + return TSDB_CODE_SUCCESS; } \ No newline at end of file From ed01ae09c67fa66bffb1b2a0ee4950521ba85903 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 29 Sep 2024 19:21:55 +0800 Subject: [PATCH 164/240] invalid read --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 75f1a6db05..27ad4aa565 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2110,7 +2110,7 @@ _err: } int32_t initCb(void* thrd, SCliReq* pReq, STransMsg* pResp) { SCliThrd* pThrd = thrd; - if (pReq->ctx == NULL) { + if (pReq->ctx == NULL || pReq->ctx->epSet == NULL) { return 0; } return cliMayCvtFqdnToIp(pReq->ctx->epSet, pThrd->pCvtAddr); @@ -2699,7 +2699,7 @@ void cliMayResetRespCode(SCliReq* pReq, STransMsg* pResp) { } // check whole vnodes is offline on this vgroup - if (pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps || pCtx->retryStep > 0) { + if (((pCtx->epSet != NULL) && pCtx->epsetRetryCnt >= pCtx->epSet->numOfEps) || pCtx->retryStep > 0) { if (pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { pResp->code = TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED; } else if (pResp->code == TSDB_CODE_RPC_BROKEN_LINK) { From 0277f22f3ec62675576f8674e8674719df83b6f9 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 30 Sep 2024 07:50:51 +0800 Subject: [PATCH 165/240] add config --- include/common/tglobal.h | 35 ++++++++++--------- source/client/src/clientEnv.c | 3 +- source/common/src/tglobal.c | 20 ++++++++++- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 8 ++--- 4 files changed, 43 insertions(+), 23 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index bece14c17d..16f0de2b00 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -42,21 +42,21 @@ typedef enum { } EEncryptScope; // cluster -extern char tsFirst[]; -extern char tsSecond[]; -extern char tsLocalFqdn[]; -extern char tsLocalEp[]; -extern char tsVersionName[]; -extern uint16_t tsServerPort; -extern int32_t tsVersion; -extern int32_t tsStatusInterval; -extern int32_t tsNumOfSupportVnodes; -extern char tsEncryptAlgorithm[]; -extern char tsEncryptScope[]; -extern EEncryptAlgor tsiEncryptAlgorithm; -extern EEncryptScope tsiEncryptScope; -//extern char tsAuthCode[]; -extern char tsEncryptKey[]; +extern char tsFirst[]; +extern char tsSecond[]; +extern char tsLocalFqdn[]; +extern char tsLocalEp[]; +extern char tsVersionName[]; +extern uint16_t tsServerPort; +extern int32_t tsVersion; +extern int32_t tsStatusInterval; +extern int32_t tsNumOfSupportVnodes; +extern char tsEncryptAlgorithm[]; +extern char tsEncryptScope[]; +extern EEncryptAlgor tsiEncryptAlgorithm; +extern EEncryptScope tsiEncryptScope; +// extern char tsAuthCode[]; +extern char tsEncryptKey[]; // common extern int32_t tsMaxShellConns; @@ -71,6 +71,7 @@ extern int32_t tsTagFilterResCacheSize; // queue & threads extern int32_t tsNumOfRpcThreads; extern int32_t tsNumOfRpcSessions; +extern int32_t tsShareConnLimit; extern int32_t tsTimeToGetAvailableConn; extern int32_t tsKeepAliveIdle; extern int32_t tsNumOfCommitThreads; @@ -264,8 +265,8 @@ extern bool tsExperimental; 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 taosReadDataFolder(const char *cfgDir, const char **envCmd, - const char *envFile, char *apolloUrl, SArray *pArgs); +int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, + SArray *pArgs); int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc); void taosCleanupCfg(); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 2ced1a6ac5..1f5f5499a8 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -370,8 +370,9 @@ int32_t openTransporter(const char *user, const char *auth, int32_t numOfThread, connLimitNum = TMAX(connLimitNum, 10); connLimitNum = TMIN(connLimitNum, 1000); rpcInit.connLimitNum = connLimitNum; - rpcInit.shareConnLimit = 8; + rpcInit.shareConnLimit = tsShareConnLimit; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; + rpcInit.startReadTimer = 1; int32_t code = taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 7f85787428..db9228477d 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -56,6 +56,7 @@ int32_t tsShellActivityTimer = 3; // second // queue & threads int32_t tsNumOfRpcThreads = 1; int32_t tsNumOfRpcSessions = 30000; +int32_t tsShareConnLimit = 8; int32_t tsTimeToGetAvailableConn = 500000; int32_t tsKeepAliveIdle = 60; @@ -572,7 +573,8 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "compressMsgSize", tsCompressMsgSize, -1, 100000000, CFG_SCOPE_BOTH, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "queryPolicy", tsQueryPolicy, 1, 4, CFG_SCOPE_CLIENT, CFG_DYN_ENT_CLIENT)); - TAOS_CHECK_RETURN(cfgAddBool(pCfg, "queryTableNotExistAsEmpty", tsQueryTbNotExistAsEmpty, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); + TAOS_CHECK_RETURN( + cfgAddBool(pCfg, "queryTableNotExistAsEmpty", tsQueryTbNotExistAsEmpty, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "enableQueryHb", tsEnableQueryHb, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "enableScience", tsEnableScience, CFG_SCOPE_CLIENT, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "querySmaOptimize", tsQuerySmaOptimize, 0, 1, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); @@ -611,6 +613,9 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { tsNumOfRpcSessions = TRANGE(tsNumOfRpcSessions, 100, 100000); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfRpcSessions", tsNumOfRpcSessions, 1, 100000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 256); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "shareConnLimit", tsShareConnLimit, 1, 256, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 10000000); TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "timeToGetAvailableConn", tsTimeToGetAvailableConn, 20, 1000000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); @@ -883,6 +888,13 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } + pItem = cfgGetItem(pCfg, "shareConnLimit"); + if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { + tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 256); + pItem->i32 = tsShareConnLimit; + pItem->stype = stype; + } + pItem = cfgGetItem(pCfg, "timeToGetAvailableConn"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 1000000); @@ -1257,6 +1269,9 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcSessions"); tsNumOfRpcSessions = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "shareConnLimit"); + tsShareConnLimit = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); tsTimeToGetAvailableConn = pItem->i32; @@ -1358,6 +1373,9 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "numOfRpcSessions"); tsNumOfRpcSessions = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "shareConnLimit"); + tsShareConnLimit = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); tsTimeToGetAvailableConn = pItem->i32; diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index b0e36a153c..c01e016e0c 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -404,7 +404,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.shareConnLimit = 16; + rpcInit.shareConnLimit = tsShareConnLimit * 2; rpcInit.shareConn = 1; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.notWaitAvaliableConn = 0; @@ -454,7 +454,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.shareConnLimit = 32; + rpcInit.shareConnLimit = tsShareConnLimit * 2; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.startReadTimer = 1; @@ -503,7 +503,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) { rpcInit.connLimitNum = connLimitNum; rpcInit.connLimitLock = 1; rpcInit.supportBatch = 1; - rpcInit.shareConnLimit = 64; + rpcInit.shareConnLimit = tsShareConnLimit * 8; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.startReadTimer = 1; @@ -560,7 +560,7 @@ int32_t dmInitServer(SDnode *pDnode) { rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.parent = pDnode; rpcInit.compressSize = tsCompressMsgSize; - rpcInit.shareConnLimit = 16; + rpcInit.shareConnLimit = tsShareConnLimit * 16; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); From d379d8994e6e5d323ba28b5751eb558678ecad8a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 30 Sep 2024 09:38:21 +0800 Subject: [PATCH 166/240] add config --- source/libs/transport/src/transCli.c | 2 +- source/libs/transport/src/transSvr.c | 31 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 27ad4aa565..1aafd71e67 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -285,7 +285,7 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); static FORCE_INLINE int32_t destroyAllReqs(SCliConn* SCliConn); -static FORCE_INLINE bool filterAllReq(void* e, void* arg); +static FORCE_INLINE bool filterAllReq(void* key, void* arg); static FORCE_INLINE bool filerBySeq(void* key, void* arg); static FORCE_INLINE bool filterByQid(void* key, void* arg); static FORCE_INLINE bool filterToDebug_timeoutMsg(void* key, void* arg); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 926fca7425..1ecf8eb247 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -441,23 +441,23 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { int64_t qId = taosHton64(pHead->qid); if (qId <= 0) { tError("conn %p recv release, but invalid qid:%" PRId64 "", pConn, qId); - return TSDB_CODE_RPC_NO_STATE; - } - - void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); - if (p == NULL) { code = TSDB_CODE_RPC_NO_STATE; - tTrace("conn %p recv release, and releady release by server qid:%" PRId64 "", pConn, qId); } else { - SSvrRegArg* arg = p; - (pInst->cfp)(pInst->parent, &(arg->msg), NULL); - tTrace("conn %p recv release, notify server app, qid:%" PRId64 "", pConn, qId); + void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); + if (p == NULL) { + code = TSDB_CODE_RPC_NO_STATE; + tTrace("conn %p recv release, and releady release by server qid:%" PRId64 "", pConn, qId); + } else { + SSvrRegArg* arg = p; + (pInst->cfp)(pInst->parent, &(arg->msg), NULL); + tTrace("conn %p recv release, notify server app, qid:%" PRId64 "", pConn, qId); - code = taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); - if (code != 0) { - tDebug("conn %p failed to remove qid:%" PRId64 "", pConn, qId); + code = taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); + if (code != 0) { + tDebug("conn %p failed to remove qid:%" PRId64 "", pConn, qId); + } + tTrace("conn %p clear state,qid:%" PRId64 "", pConn, qId); } - tTrace("conn %p clear state,qid:%" PRId64 "", pConn, qId); } STransMsg tmsg = {.code = code, @@ -468,7 +468,8 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { SSvrRespMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (srvMsg == NULL) { - tError("conn %p recv release, but invalid qid:%" PRId64 "", pConn, qId); + tError("conn %p recv release, failed to send release-resp since %s", pConn, terrno); + taosMemoryFree(pHead); return terrno; } srvMsg->msg = tmsg; @@ -479,7 +480,7 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { uvStartSendRespImpl(srvMsg); taosMemoryFree(pHead); - return code; + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } return 0; } From c173f5ab02525bf2ae64db85b36c901f224e58bd Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 30 Sep 2024 10:26:52 +0800 Subject: [PATCH 167/240] add config --- source/libs/transport/src/transSvr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 1ecf8eb247..c13ec1ae4e 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -468,7 +468,7 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { SSvrRespMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSvrRespMsg)); if (srvMsg == NULL) { - tError("conn %p recv release, failed to send release-resp since %s", pConn, terrno); + tError("conn %p recv release, failed to send release-resp since %s", pConn, tstrerror(terrno)); taosMemoryFree(pHead); return terrno; } From adb8251bd6fd7029af92cf0a8c9a59d04158c020 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 30 Sep 2024 11:02:13 +0800 Subject: [PATCH 168/240] add config --- source/libs/transport/src/transCli.c | 45 +++++++++++++++++++--------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1aafd71e67..c7554f02d2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1039,6 +1039,34 @@ _failed: taosMemoryFree(conn); return code; } + +static void cliDestroyAllQidFromThrd(SCliConn* conn) { + int32_t code = 0; + SCliThrd* pThrd = conn->hostThrd; + + void* pIter = taosHashIterate(conn->pQTable, NULL); + while (pIter != NULL) { + int64_t* qid = taosHashGetKey(pIter, NULL); + + code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); + if (code != 0) { + tDebug("%s conn %p failed to remove state %" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, *qid, + tstrerror(code)); + } else { + tDebug("%s conn %p destroy state %" PRId64 "", CONN_GET_INST_LABEL(conn), conn, *qid); + } + + STransCtx* ctx = pIter; + transCtxCleanup(ctx); + + transReleaseExHandle(transGetRefMgt(), *qid); + transRemoveExHandle(transGetRefMgt(), *qid); + + pIter = taosHashIterate(conn->pQTable, pIter); + } + taosHashCleanup(conn->pQTable); + conn->pQTable = NULL; +} static void cliDestroyConn(SCliConn* conn, bool clear) { cliHandleException(conn); } static void cliDestroy(uv_handle_t* handle) { int32_t code = 0; @@ -1061,20 +1089,7 @@ static void cliDestroy(uv_handle_t* handle) { taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); taosMemoryFree(conn->ipStr); - - void* pIter = taosHashIterate(conn->pQTable, NULL); - while (pIter) { - int64_t* qid = taosHashGetKey(pIter, NULL); - code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); - if (code != 0) { - tDebug("%s conn %p failed to remove state %" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, *qid, - tstrerror(code)); - } - pIter = taosHashIterate(conn->pQTable, pIter); - tDebug("%s conn %p destroy state %" PRId64 "", CONN_GET_INST_LABEL(conn), conn, *qid); - } - - destroyCliConnQTable(conn); + cliDestroyAllQidFromThrd(conn); if (conn->pInitUserReq) { taosMemoryFree(conn->pInitUserReq); @@ -1149,7 +1164,9 @@ static void cliHandleException(SCliConn* conn) { tError("%s conn %p failed to destroy all reqs on conn since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); } + cliDestroyAllQidFromThrd(conn); QUEUE_REMOVE(&conn->q); + if (conn->registered) { int8_t ref = transGetRefCount(conn); if (ref == 0 && !uv_is_closing((uv_handle_t*)conn->stream)) { From 7e11fdeed643cfd09a3d916822e98edc606942da Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 30 Sep 2024 16:56:14 +0800 Subject: [PATCH 169/240] add time out --- include/common/tglobal.h | 1 + include/libs/transport/trpc.h | 2 + source/client/src/clientEnv.c | 1 + source/client/src/clientImpl.c | 1 + source/common/src/tglobal.c | 14 + source/dnode/mgmt/node_mgmt/src/dmTransport.c | 3 + source/libs/transport/inc/transportInt.h | 1 + source/libs/transport/src/trans.c | 5 + source/libs/transport/src/transCli.c | 280 ++++++++++++++---- 9 files changed, 253 insertions(+), 55 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 16f0de2b00..59ccaf54f6 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -72,6 +72,7 @@ extern int32_t tsTagFilterResCacheSize; extern int32_t tsNumOfRpcThreads; extern int32_t tsNumOfRpcSessions; extern int32_t tsShareConnLimit; +extern int32_t tsReadTimeout; extern int32_t tsTimeToGetAvailableConn; extern int32_t tsKeepAliveIdle; extern int32_t tsNumOfCommitThreads; diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 2f6b23a594..cfa3f44f7f 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -132,6 +132,7 @@ typedef struct SRpcInit { int8_t shareConn; // 0: no share, 1. share int8_t notWaitAvaliableConn; // 1: wait to get, 0: no wait int8_t startReadTimer; + int64_t readTimeout; // s void *parent; } SRpcInit; @@ -151,6 +152,7 @@ typedef struct { SHashObj *args; SRpcBrokenlinkVal brokenVal; void (*freeFunc)(const void *arg); + int64_t st; } SRpcCtx; int32_t rpcInit(); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 1f5f5499a8..51027ca7d3 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -373,6 +373,7 @@ int32_t openTransporter(const char *user, const char *auth, int32_t numOfThread, rpcInit.shareConnLimit = tsShareConnLimit; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.startReadTimer = 1; + rpcInit.readTimeout = tsReadTimeout; int32_t code = taosVersionStrToInt(version, &(rpcInit.compatibilityVer)); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 2564d2d489..341a462a84 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -2570,6 +2570,7 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de connLimitNum = TMIN(connLimitNum, 500); rpcInit.connLimitNum = connLimitNum; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; + rpcInit.readTimeout = tsReadTimeout; if (TSDB_CODE_SUCCESS != taosVersionStrToInt(version, &(rpcInit.compatibilityVer))) { tscError("faild to convert taos version from str to int, errcode:%s", terrstr()); goto _OVER; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index db9228477d..6087af8f65 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -57,6 +57,7 @@ int32_t tsShellActivityTimer = 3; // second int32_t tsNumOfRpcThreads = 1; int32_t tsNumOfRpcSessions = 30000; int32_t tsShareConnLimit = 8; +int32_t tsReadTimeout = 128; int32_t tsTimeToGetAvailableConn = 500000; int32_t tsKeepAliveIdle = 60; @@ -616,6 +617,9 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 256); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "shareConnLimit", tsShareConnLimit, 1, 256, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsReadTimeout = TRANGE(tsReadTimeout, 0, 24 * 3600); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "readTimeout", tsShareConnLimit, 0, 24 * 3600, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 10000000); TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "timeToGetAvailableConn", tsTimeToGetAvailableConn, 20, 1000000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); @@ -895,6 +899,13 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } + pItem = cfgGetItem(pCfg, "readTimeout"); + if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { + tsShareConnLimit = TRANGE(tsShareConnLimit, 64, 24 * 3600); + pItem->i32 = tsShareConnLimit; + pItem->stype = stype; + } + pItem = cfgGetItem(pCfg, "timeToGetAvailableConn"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 1000000); @@ -1272,6 +1283,9 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "shareConnLimit"); tsShareConnLimit = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "readTimeout"); + tsReadTimeout = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); tsTimeToGetAvailableConn = pItem->i32; diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index c01e016e0c..9bf3afff76 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -409,6 +409,7 @@ int32_t dmInitClient(SDnode *pDnode) { rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.notWaitAvaliableConn = 0; rpcInit.startReadTimer = 1; + rpcInit.readTimeout = tsReadTimeout; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); @@ -457,6 +458,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.shareConnLimit = tsShareConnLimit * 2; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.startReadTimer = 1; + rpcInit.readTimeout = 0; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); @@ -506,6 +508,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) { rpcInit.shareConnLimit = tsShareConnLimit * 8; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; rpcInit.startReadTimer = 1; + rpcInit.readTimeout = tsReadTimeout; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { dError("failed to convert version string:%s to int", version); diff --git a/source/libs/transport/inc/transportInt.h b/source/libs/transport/inc/transportInt.h index cf0ccd9fb2..39afb29342 100644 --- a/source/libs/transport/inc/transportInt.h +++ b/source/libs/transport/inc/transportInt.h @@ -79,6 +79,7 @@ typedef struct { int64_t refId; int8_t shareConn; int8_t startReadTimer; + int64_t readTimeout; TdThreadMutex mutex; } SRpcInfo; diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 862f3d0adb..a479920360 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -84,6 +84,11 @@ void* rpcOpen(const SRpcInit* pInit) { pRpc->shareConnLimit = BUFFER_LIMIT; } + pRpc->readTimeout = pInit->readTimeout; + if (pRpc->readTimeout <= 0) { + pRpc->readTimeout = INT64_MAX; + } + pRpc->numOfThreads = pInit->numOfThreads > TSDB_MAX_RPC_THREADS ? TSDB_MAX_RPC_THREADS : pInit->numOfThreads; if (pRpc->numOfThreads <= 0) { pRpc->numOfThreads = 1; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c7554f02d2..27cbc313bf 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -27,6 +27,7 @@ typedef struct { typedef struct SConnList { queue conns; int32_t size; + int32_t totaSize; } SConnList; typedef struct { @@ -65,7 +66,6 @@ typedef struct SCliConn { SConnBuffer readBuf; STransQueue reqsToSend; STransQueue reqsSentOut; - SHashObj* pQueryTable; queue q; SConnList* list; @@ -162,6 +162,8 @@ typedef struct SCliThrd { int32_t (*notifyExceptCb)(void* arg, SCliReq* pReq, STransMsg* pResp); SHashObj* pIdConnTable; // + + SArray* pQIdBuf; // tmp buf to avoid alloc buf; } SCliThrd; typedef struct SCliObj { @@ -267,6 +269,7 @@ static int32_t cliHandleState_mayUpdateState(SCliConn* pConn, SCliReq* pReq); static int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead); static int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, STransMsg* pResp); static int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq); +static int32_t cliHandleState_mayUpdateStateTime(SCliConn* pConn, SCliReq* pReq); int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); @@ -285,11 +288,17 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); static FORCE_INLINE int32_t destroyAllReqs(SCliConn* SCliConn); +typedef struct SListFilterArg { + int64_t id; + STrans* pInst; +} SListFilterArg; + static FORCE_INLINE bool filterAllReq(void* key, void* arg); static FORCE_INLINE bool filerBySeq(void* key, void* arg); static FORCE_INLINE bool filterByQid(void* key, void* arg); static FORCE_INLINE bool filterToDebug_timeoutMsg(void* key, void* arg); static FORCE_INLINE bool filterToRmTimoutReq(void* key, void* arg); +static FORCE_INLINE bool filterTimeoutReq(void* key, void* arg); typedef struct { void* p; @@ -378,7 +387,7 @@ void cliResetConnTimer(SCliConn* conn) { } } -void cliConnMayUpdateTimer(SCliConn* conn, int timeout) { +void cliConnMayUpdateTimer(SCliConn* conn, int64_t timeout) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; if (pInst->startReadTimer == 0) { @@ -550,6 +559,7 @@ int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, ST } STransCtx* pCtx = taosHashGet(conn->pQTable, &qId, sizeof(qId)); + pCtx->st = taosGetTimestampUs(); if (pCtx == 0) { return TSDB_CODE_RPC_NO_STATE; } @@ -624,6 +634,12 @@ void cliHandleResp(SCliConn* conn) { } return; } + } else { + code = cliHandleState_mayUpdateStateTime(conn, pReq); + if (code != 0) { + tDebug("%s conn %p failed to update state time qid:" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, qId, + tstrerror(code)); + } } code = cliBuildRespFromCont(pReq, &resp, pHead); @@ -642,7 +658,7 @@ void cliHandleResp(SCliConn* conn) { } cliConnCheckTimoutMsg(conn); - cliConnMayUpdateTimer(conn, READ_TIMEOUT); + cliConnMayUpdateTimer(conn, pInst->readTimeout); } void cliConnTimeout(uv_timer_t* handle) { @@ -659,10 +675,11 @@ void cliConnTimeout(uv_timer_t* handle) { } bool filterToRmTimoutReq(void* key, void* arg) { - SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + SListFilterArg* filterArg = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { - int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000); - if (elapse > READ_TIMEOUT) { + int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000000); + if (filterArg && (elapse > filterArg->pInst->readTimeout)) { return false; } else { return false; @@ -672,10 +689,11 @@ bool filterToRmTimoutReq(void* key, void* arg) { } bool filterToDebug_timeoutMsg(void* key, void* arg) { - SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + SListFilterArg* filterArg = arg; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { - int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000); - if (elapse > READ_TIMEOUT) { + int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000000); + if (filterArg && elapse > filterArg->pInst->readTimeout) { tWarn("req %s timeout, elapse:%" PRId64 "ms", TMSG_INFO(pReq->msg.msgType), elapse); return false; } @@ -702,7 +720,8 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { } QUEUE_INIT(&set); - transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmTimoutReq, NULL, &set, -1); + SListFilterArg arg = {.id = 0, .pInst = pInst}; + transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmTimoutReq, &arg, &set, -1); while (!QUEUE_IS_EMPTY(&set)) { queue* el = QUEUE_HEAD(&set); @@ -804,6 +823,7 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p if (plist->size >= pInst->connLimitNum) { return TSDB_CODE_RPC_MAX_SESSIONS; } + plist->totaSize += 1; return TSDB_CODE_RPC_NETWORK_BUSY; } @@ -1086,6 +1106,11 @@ static void cliDestroy(uv_handle_t* handle) { if (code != 0) { tDebug("%s conn %p failed to del conn from heapcach since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); } + + if (conn->list) { + conn->list->totaSize -= 1; + conn->list = NULL; + } taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); taosMemoryFree(conn->ipStr); @@ -1107,6 +1132,56 @@ static void cliDestroy(uv_handle_t* handle) { static FORCE_INLINE bool filterAllReq(void* e, void* arg) { return 1; } +static void notifyAndDestroyReq(SCliConn* pConn, SCliReq* pReq, int32_t code) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + SReqCtx* pCtx = pReq ? pReq->ctx : NULL; + STransMsg resp = {0}; + resp.code = (pConn->connnected ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL); + if (code != 0) { + resp.code = code; + } + + resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; + resp.info.cliVer = pInst->compatibilityVer; + resp.info.ahandle = pCtx ? pCtx->ahandle : 0; + resp.info.handle = pReq->msg.info.handle; + if (pReq) { + resp.info.traceId = pReq->msg.info.traceId; + } + + STraceId* trace = &resp.info.traceId; + tDebug("%s conn %p notify user and destroy msg %s since %s", CONN_GET_INST_LABEL(pConn), pConn, + TMSG_INFO(pReq->msg.msgType), tstrerror(resp.code)); + + // handle noresp and inter manage msg + if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { + tDebug("%s conn %p destroy msg directly since %s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msg.msgType), + tstrerror(resp.code)); + destroyReq(pReq); + return; + } + + pReq->seq = 0; + code = cliNotifyCb(pConn, pReq, &resp); + if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + return; + } else { + // already notify user + destroyReq(pReq); + } +} + +static FORCE_INLINE void destroyReqInQueue(SCliConn* conn, queue* set) { + while (!QUEUE_IS_EMPTY(&set)) { + queue* el = QUEUE_HEAD(&set); + QUEUE_REMOVE(el); + + SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + notifyAndDestroyReq(conn, pReq, 0); + } +} static FORCE_INLINE int32_t destroyAllReqs(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; @@ -1119,38 +1194,7 @@ static FORCE_INLINE int32_t destroyAllReqs(SCliConn* conn) { transQueueRemoveByFilter(&conn->reqsSentOut, filterAllReq, NULL, &set, -1); transQueueRemoveByFilter(&conn->reqsToSend, filterAllReq, NULL, &set, -1); - while (!QUEUE_IS_EMPTY(&set)) { - queue* el = QUEUE_HEAD(&set); - QUEUE_REMOVE(el); - - SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); - - SReqCtx* pCtx = pReq ? pReq->ctx : NULL; - STransMsg resp = {0}; - resp.code = (conn->connnected ? TSDB_CODE_RPC_BROKEN_LINK : TSDB_CODE_RPC_NETWORK_UNAVAIL); - resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; - resp.info.cliVer = pInst->compatibilityVer; - resp.info.ahandle = pCtx ? pCtx->ahandle : 0; - resp.info.handle = pReq->msg.info.handle; - if (pReq) { - resp.info.traceId = pReq->msg.info.traceId; - } - - // handle noresp and inter manage msg - if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { - destroyReq(pReq); - continue; - } - - pReq->seq = 0; - code = cliNotifyCb(conn, pReq, &resp); - if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { - continue; - } else { - // already notify user - destroyReq(pReq); - } - } + destroyReqInQueue(conn, &set); return 0; } static void cliHandleException(SCliConn* conn) { @@ -1166,6 +1210,10 @@ static void cliHandleException(SCliConn* conn) { cliDestroyAllQidFromThrd(conn); QUEUE_REMOVE(&conn->q); + if (conn->list) { + conn->list->totaSize -= 1; + conn->list = NULL; + } if (conn->registered) { int8_t ref = transGetRefCount(conn); @@ -1203,6 +1251,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { SCliConn* conn = wrapper->arg; SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; freeWReqToWQ(&conn->wq, wrapper); @@ -1217,7 +1266,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { return; } - cliConnMayUpdateTimer(conn, READ_TIMEOUT); + cliConnMayUpdateTimer(conn, pInst->readTimeout); if (conn->readerStart == 0) { code = uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); if (code != 0) { @@ -1709,6 +1758,16 @@ static void doFreeTimeoutMsg(void* param) { taosMemoryFree(arg); } +int32_t cliHandleState_mayUpdateStateTime(SCliConn* pConn, SCliReq* pReq) { + int64_t qid = pReq->msg.info.qId; + if (qid > 0) { + STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); + if (pUserCtx != NULL) { + pUserCtx->st = taosGetTimestampUs(); + } + } + return 0; +} int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq) { int32_t code = 0; int64_t qid = pReq->msg.info.qId; @@ -1721,14 +1780,17 @@ int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq) { STransCtx* pUserCtx = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (pUserCtx == NULL) { + pCtx->userCtx.st = taosGetTimestampUs(); code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &pCtx->userCtx, sizeof(pCtx->userCtx)); tDebug("%s conn %p succ to add statue ctx, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } else { transCtxMerge(pUserCtx, &pCtx->userCtx); + pUserCtx->st = taosGetTimestampUs(); tDebug("%s conn %p succ to update statue ctx, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } return 0; } + int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { int32_t code = 0; int64_t qid = pReq->msg.info.qId; @@ -2247,6 +2309,11 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); } + pThrd->pQIdBuf = taosArrayInit(8, sizeof(int64_t)); + if (pThrd->pQIdBuf == NULL) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + } + pThrd->initCb = initCb; pThrd->notifyCb = notfiyCb; pThrd->notifyExceptCb = notifyExceptCb; @@ -2281,6 +2348,7 @@ _end: taosHashCleanup(pThrd->failFastCache); taosHashCleanup(pThrd->batchCache); taosHashCleanup(pThrd->pIdConnTable); + taosArrayDestroy(pThrd->pQIdBuf); taosMemoryFree(pThrd); } @@ -2343,6 +2411,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { taosHashCleanup(pThrd->pIdConnTable); taosMemoryFree(pThrd->pCvtAddr); + taosArrayDestroy(pThrd->pQIdBuf); taosMemoryFree(pThrd); } @@ -3442,12 +3511,119 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea return code; } -static FORCE_INLINE int8_t shouldSWitchToOtherConn(STrans* pInst, int32_t reqNum, int32_t sentNum, int32_t stateNum) { - int32_t total = reqNum + sentNum; - if (stateNum >= pInst->shareConnLimit) { - return 1; +bool filterTimeoutReq(void* key, void* arg) { + SListFilterArg* listArg = arg; + if (listArg == NULL) { + return false; } - if (total >= pInst->shareConnLimit) { + + int64_t st = listArg->id; + SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); + if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { + int64_t elapse = ((st - pReq->st) / 1000000); + if (listArg && elapse > listArg->pInst->readTimeout) { + return true; + } else { + return false; + } + } + return false; +} + +static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) { + int32_t code = 0; + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + SArray* pQIdBuf = pThrd->pQIdBuf; + void* pIter = taosHashIterate(pConn->pQTable, NULL); + while (pIter) { + STransCtx* pCtx = (STransCtx*)pIter; + int64_t* qid = taosHashGetKey(pIter, NULL); + + if (((*st - pCtx->st) / 1000000) > pInst->readTimeout) { + code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); + if (code != 0) { + tError("%s conn %p failed to remove state qid:" PRId64 " since %s", tstrerror(code)); + } + + transReleaseExHandle(transGetRefMgt(), *qid); + transRemoveExHandle(transGetRefMgt(), *qid); + + if (taosArrayPush(pQIdBuf, qid) == NULL) { + code = terrno; + tError("%s conn %p failed to add qid:" PRId64 " since %s", tstrerror(code)); + break; + } + } + taosHashIterate(pConn->pQTable, pIter); + } + + for (int32_t i = 0; i < taosArrayGetSize(pQIdBuf); i++) { + int64_t* qid = taosArrayGet(pQIdBuf, i); + transQueueRemoveByFilter(&pConn->reqsSentOut, filterByQid, qid, &set, -1); + transQueueRemoveByFilter(&pConn->reqsToSend, filterByQid, qid, &set, -1); + + STransCtx* p = taosHashGet(pConn->pQTable, qid, sizeof(*qid)); + transCtxCleanup(p); + code = taosHashRemove(pConn->pQTable, qid, sizeof(*qid)); + if (code != 0) { + tError("%s conn %p failed to drop ctx of qid:" PRId64 " since %s", tstrerror(code)); + } + } + + taosArrayClear(pQIdBuf); +} + +static void cliConnRemoveTimeoutNoQidMsg(SCliConn* pConn, int64_t* st, queue* set) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + SListFilterArg arg = {.id = *st, .pInst = pInst}; + transQueueRemoveByFilter(&pConn->reqsToSend, filterTimeoutReq, st, &set, -1); + return; +} + +static int8_t cliConnRemoveTimeoutMsg(SCliConn* pConn) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + queue set; + QUEUE_INIT(&set); + + int64_t now = taosGetTimestampUs(); + + cliConnRemoveTimoutQidMsg(pConn, &now, &set); + cliConnRemoveTimeoutNoQidMsg(pConn, &now, &set); + + if (QUEUE_IS_EMPTY(&set)) { + return 0; + } + tDebug("%s conn %p do remove timeout msg", pInst->label, pConn); + destroyReqInQueue(pConn, &set); + return 1; +} +static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + + tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); + int32_t reqsNum = transQueueSize(&pConn->reqsToSend); + int32_t reqsSentOut = transQueueSize(&pConn->reqsSentOut); + int32_t stateNum = taosHashGetSize(pConn->pQTable); + int32_t totalReqs = reqsNum + reqsSentOut; + + if (stateNum >= pInst->shareConnLimit || totalReqs >= pInst->shareConnLimit) { + if (pConn->list == NULL && pConn->dstAddr != NULL) { + pConn->list = taosHashGet((SHashObj*)pThrd->pool, pConn->dstAddr, strlen(pConn->dstAddr)); + } + if (pConn->list && pConn->list->totaSize >= pInst->connLimitNum / 4) { + tWarn("%s conn %p try to remove timeout msg since too many conn created", transLabel(pInst), pConn); + if (cliConnRemoveTimeoutMsg(pConn)) { + tDebug("%s conn %p succ to remove timeout msg", transLabel(pInst), pConn); + } + return 1; + } + // check req timeout or not return 1; } @@ -3487,13 +3663,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; } else { - tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); - int32_t reqsNum = transQueueSize(&pConn->reqsToSend); - int32_t reqsSentOut = transQueueSize(&pConn->reqsSentOut); - int32_t stateNum = taosHashGetSize(pConn->pQTable); - SCliThrd* pThrd = pConn->hostThrd; - STrans* pInst = pThrd->pInst; - if (shouldSWitchToOtherConn(pInst, reqsNum, reqsSentOut, stateNum)) { + if (shouldSWitchToOtherConn(pConn, key)) { logConnMissHit(pConn); return NULL; } From f3dda4f7795c25abd056d2ad788b37ff98c3fddc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 30 Sep 2024 17:42:12 +0800 Subject: [PATCH 170/240] add time out --- source/libs/transport/src/transCli.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 27cbc313bf..4f44b86ef5 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -637,7 +637,7 @@ void cliHandleResp(SCliConn* conn) { } else { code = cliHandleState_mayUpdateStateTime(conn, pReq); if (code != 0) { - tDebug("%s conn %p failed to update state time qid:" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, qId, + tDebug("%s conn %p failed to update state time qid:%" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, qId, tstrerror(code)); } } @@ -1157,8 +1157,8 @@ static void notifyAndDestroyReq(SCliConn* pConn, SCliReq* pReq, int32_t code) { // handle noresp and inter manage msg if (pCtx == NULL || REQUEST_NO_RESP(&pReq->msg)) { - tDebug("%s conn %p destroy msg directly since %s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msg.msgType), - tstrerror(resp.code)); + tDebug("%s conn %p destroy %s msg directly since %s", CONN_GET_INST_LABEL(pConn), pConn, + TMSG_INFO(pReq->msg.msgType), tstrerror(resp.code)); destroyReq(pReq); return; } @@ -3544,7 +3544,8 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) if (((*st - pCtx->st) / 1000000) > pInst->readTimeout) { code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); if (code != 0) { - tError("%s conn %p failed to remove state qid:" PRId64 " since %s", tstrerror(code)); + tError("%s conn %p failed to remove state qid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tstrerror(code)); } transReleaseExHandle(transGetRefMgt(), *qid); @@ -3552,7 +3553,8 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) if (taosArrayPush(pQIdBuf, qid) == NULL) { code = terrno; - tError("%s conn %p failed to add qid:" PRId64 " since %s", tstrerror(code)); + tError("%s conn %p failed to add qid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tstrerror(code)); break; } } @@ -3568,7 +3570,8 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) transCtxCleanup(p); code = taosHashRemove(pConn->pQTable, qid, sizeof(*qid)); if (code != 0) { - tError("%s conn %p failed to drop ctx of qid:" PRId64 " since %s", tstrerror(code)); + tError("%s conn %p failed to drop ctx of qid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tstrerror(code)); } } From d24dc87c8036b940044be982fc993b0d1c39fc34 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 30 Sep 2024 17:55:13 +0800 Subject: [PATCH 171/240] add time out --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4f44b86ef5..1cc7afb04e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3558,7 +3558,7 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) break; } } - taosHashIterate(pConn->pQTable, pIter); + pIter = taosHashIterate(pConn->pQTable, pIter); } for (int32_t i = 0; i < taosArrayGetSize(pQIdBuf); i++) { From 60718d0e38d32dee1b029e8ca8412134314b35b6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 30 Sep 2024 18:17:04 +0800 Subject: [PATCH 172/240] add time out --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1cc7afb04e..c0b397b64b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1174,8 +1174,8 @@ static void notifyAndDestroyReq(SCliConn* pConn, SCliReq* pReq, int32_t code) { } static FORCE_INLINE void destroyReqInQueue(SCliConn* conn, queue* set) { - while (!QUEUE_IS_EMPTY(&set)) { - queue* el = QUEUE_HEAD(&set); + while (!QUEUE_IS_EMPTY(set)) { + queue* el = QUEUE_HEAD(set); QUEUE_REMOVE(el); SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); From 947e1d2fc4cad7be40fada63a77aadcd32c3f229 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 1 Oct 2024 10:06:52 +0800 Subject: [PATCH 173/240] add config --- source/libs/transport/src/transCli.c | 50 +++++++++++++++------------ source/libs/transport/src/transComm.c | 2 +- source/libs/transport/src/transSvr.c | 34 +++++++++--------- 3 files changed, 45 insertions(+), 41 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index c0b397b64b..59104d6908 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -509,7 +509,7 @@ int32_t cliHandleState_mayHandleReleaseResp(SCliConn* conn, STransMsgHead* pHead int64_t qId = taosHton64(pHead->qid); STraceId* trace = &pHead->traceId; int64_t seqNum = taosHton64(pHead->seqNum); - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seqNum:%" PRId64 ", qid:%" PRId64 "", + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seqNum:%" PRId64 ", sid:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, pHead->msgLen, seqNum, qId); @@ -565,7 +565,7 @@ int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, ST } STraceId* trace = &pHead->traceId; pResp->info.ahandle = transCtxDumpVal(pCtx, pHead->msgType); - tGDebug("%s conn %p %s received from %s, local info:%s, qid:%" PRId64 ", create ahandle %p by %s", + tGDebug("%s conn %p %s received from %s, local info:%s, sid:%" PRId64 ", create ahandle %p by %s", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), conn->dst, conn->src, qId, pResp->info.ahandle, TMSG_INFO(pHead->msgType)); return 0; @@ -624,7 +624,7 @@ void cliHandleResp(SCliConn* conn) { return; } if (code != 0) { - tWarn("%s conn %p recv unexpected packet, msgType:%s, seqNum:%" PRId64 ", qId:%" PRId64 + tWarn("%s conn %p recv unexpected packet, msgType:%s, seqNum:%" PRId64 ", sid:%" PRId64 ", the sever may sends repeated response since %s", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), seq, qId, tstrerror(code)); // TODO: notify cb @@ -637,14 +637,14 @@ void cliHandleResp(SCliConn* conn) { } else { code = cliHandleState_mayUpdateStateTime(conn, pReq); if (code != 0) { - tDebug("%s conn %p failed to update state time qid:%" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, qId, + tDebug("%s conn %p failed to update state time sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, qId, tstrerror(code)); } } code = cliBuildRespFromCont(pReq, &resp, pHead); STraceId* trace = &resp.info.traceId; - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%" PRId64 ", qid:%" PRId64 "", + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, seq:%" PRId64 ", sid:%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(resp.msgType), conn->dst, conn->src, pHead->msgLen, seq, qId); code = cliNotifyCb(conn, pReq, &resp); @@ -803,6 +803,7 @@ static int32_t getOrCreateConnList(SCliThrd* pThrd, const char* key, SConnList** } QUEUE_INIT(&plist->conns); *ppList = plist; + tDebug("create conn list %p for key %s", plist, key); } else { *ppList = plist; } @@ -1073,7 +1074,7 @@ static void cliDestroyAllQidFromThrd(SCliConn* conn) { tDebug("%s conn %p failed to remove state %" PRId64 " since %s", CONN_GET_INST_LABEL(conn), conn, *qid, tstrerror(code)); } else { - tDebug("%s conn %p destroy state %" PRId64 "", CONN_GET_INST_LABEL(conn), conn, *qid); + tDebug("%s conn %p destroy sid::%" PRId64 "", CONN_GET_INST_LABEL(conn), conn, *qid); } STransCtx* ctx = pIter; @@ -1093,10 +1094,13 @@ static void cliDestroy(uv_handle_t* handle) { if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) { return; } + SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; cliResetConnTimer(conn); + tDebug("%s conn %p try to destroy", CONN_GET_INST_LABEL(conn), conn); + code = destroyAllReqs(conn); if (code != 0) { tDebug("%s conn %p failed to all reqs since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); @@ -1107,10 +1111,6 @@ static void cliDestroy(uv_handle_t* handle) { tDebug("%s conn %p failed to del conn from heapcach since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); } - if (conn->list) { - conn->list->totaSize -= 1; - conn->list = NULL; - } taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); taosMemoryFree(conn->ipStr); @@ -1392,7 +1392,7 @@ int32_t cliBatchSend(SCliConn* pConn) { pCliMsg->seq = pConn->seq; STraceId* trace = &pCliMsg->msg.info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%" PRId64 ", qid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), + tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%" PRId64 ", sid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); } @@ -1774,7 +1774,7 @@ int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq) { SReqCtx* pCtx = pReq->ctx; SCliThrd* pThrd = pConn->hostThrd; if (pCtx == NULL) { - tDebug("%s conn %p not need to update statue ctx, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p not need to update statue ctx, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); return 0; } @@ -1782,11 +1782,11 @@ int32_t cliHandleState_mayUpdateStateCtx(SCliConn* pConn, SCliReq* pReq) { if (pUserCtx == NULL) { pCtx->userCtx.st = taosGetTimestampUs(); code = taosHashPut(pConn->pQTable, &qid, sizeof(qid), &pCtx->userCtx, sizeof(pCtx->userCtx)); - tDebug("%s conn %p succ to add statue ctx, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to add statue ctx, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } else { transCtxMerge(pUserCtx, &pCtx->userCtx); pUserCtx->st = taosGetTimestampUs(); - tDebug("%s conn %p succ to update statue ctx, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to update statue ctx, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } return 0; } @@ -1809,12 +1809,12 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn) { transReleaseExHandle(transGetRefMgt(), qid); return TSDB_CODE_RPC_STATE_DROPED; } - tDebug("%s conn %p failed to get statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p failed to get statue, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); transReleaseExHandle(transGetRefMgt(), qid); return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } else { *pConn = pState->conn; - tDebug("%s conn %p succ to get conn of statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to get conn of statue, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } transReleaseExHandle(transGetRefMgt(), qid); return 0; @@ -1832,9 +1832,9 @@ int32_t cliHandleState_mayUpdateState(SCliConn* pConn, SCliReq* pReq) { SReqState state = {.conn = pConn, .arg = NULL}; code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); if (code != 0) { - tDebug("%s conn %p failed to statue, qid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p failed to statue, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); } else { - tDebug("%s conn %p succ to add statue, qid:%" PRId64 " (1)", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p succ to add statue, sid:%" PRId64 " (1)", transLabel(pThrd->pInst), pConn, qid); } TAOS_UNUSED(cliHandleState_mayUpdateStateCtx(pConn, pReq)); @@ -3107,6 +3107,7 @@ int32_t transSendRequestWithId(void* pInstRef, const SEpSet* pEpSet, STransMsg* transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } + transReleaseExHandle(transGetRefMgt(), *transpointId); transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; @@ -3438,7 +3439,7 @@ int32_t transAllocHandle(int64_t* refId) { QUEUE_INIT(&exh->q); taosInitRWLatch(&exh->latch); - tDebug("trans alloc qid:%" PRId64 ", malloc:%p", exh->refId, exh); + tDebug("trans alloc sid:%" PRId64 ", malloc:%p", exh->refId, exh); *refId = exh->refId; return 0; } @@ -3470,7 +3471,7 @@ int32_t transFreeConnById(void* pInstRef, int64_t transpointId) { pCli->msg = msg; STraceId* trace = &pCli->msg.info.traceId; - tGDebug("%s start to free conn qid:%" PRId64 "", pInst->label, transpointId); + tGDebug("%s start to free conn sid:%" PRId64 "", pInst->label, transpointId); code = transAsyncSend(pThrd->asyncPool, &pCli->q); if (code != 0) { @@ -3544,7 +3545,7 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) if (((*st - pCtx->st) / 1000000) > pInst->readTimeout) { code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); if (code != 0) { - tError("%s conn %p failed to remove state qid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tError("%s conn %p failed to remove state sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, tstrerror(code)); } @@ -3553,7 +3554,7 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) if (taosArrayPush(pQIdBuf, qid) == NULL) { code = terrno; - tError("%s conn %p failed to add qid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tError("%s conn %p failed to add sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, tstrerror(code)); break; } @@ -3570,7 +3571,7 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) transCtxCleanup(p); code = taosHashRemove(pConn->pQTable, qid, sizeof(*qid)); if (code != 0) { - tError("%s conn %p failed to drop ctx of qid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, + tError("%s conn %p failed to drop ctx of sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, tstrerror(code)); } } @@ -3618,6 +3619,9 @@ static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { if (stateNum >= pInst->shareConnLimit || totalReqs >= pInst->shareConnLimit) { if (pConn->list == NULL && pConn->dstAddr != NULL) { pConn->list = taosHashGet((SHashObj*)pThrd->pool, pConn->dstAddr, strlen(pConn->dstAddr)); + if (pConn->list != NULL) { + tDebug("conn %p get list %p from pool for key:%s", pConn, pConn->list, key); + } } if (pConn->list && pConn->list->totaSize >= pInst->connLimitNum / 4) { tWarn("%s conn %p try to remove timeout msg since too many conn created", transLabel(pInst), pConn); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index a149a32d96..20adaebf84 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -764,7 +764,7 @@ void transDestroyExHandle(void* handle) { return; } SExHandle* eh = handle; - tDebug("trans destroy qid:%" PRId64 ", memory %p", eh->refId, handle); + tDebug("trans destroy sid:%" PRId64 ", memory %p", eh->refId, handle); taosMemoryFree(handle); } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index c13ec1ae4e..d67e908e2a 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -394,11 +394,11 @@ static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* if (pConn->status == ConnNormal && pHead->noResp == 0) { if (cost >= EXCEPTION_LIMIT_US) { tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, recv exception, seqNum:%" PRId64 - ", qid:%" PRId64 "", + ", sid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); } else { - tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, seqNum:%" PRId64 ", qid:%" PRId64 "", + tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, cost:%dus, seqNum:%" PRId64 ", sid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, (int)cost, pTransMsg->info.seqNum, pTransMsg->info.qId); } @@ -406,13 +406,13 @@ static void uvPerfLog_receive(SSvrConn* pConn, STransMsgHead* pHead, STransMsg* if (cost >= EXCEPTION_LIMIT_US) { tGDebug( "%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, recv exception, " - "seqNum:%" PRId64 ", qid:%" PRId64 "", + "seqNum:%" PRId64 ", sid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); } else { tGDebug("%s conn %p %s received from %s, local info:%s, len:%d, noResp:%d, code:%d, cost:%dus, seqNum:%" PRId64 ", " - "qid:%" PRId64 "", + "sid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pTransMsg->msgType), pConn->dst, pConn->src, pTransMsg->contLen, pHead->noResp, pTransMsg->code, (int)(cost), pTransMsg->info.seqNum, pTransMsg->info.qId); } @@ -440,23 +440,23 @@ static int32_t uvMayHandleReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { if (pHead->msgType == TDMT_SCH_TASK_RELEASE) { int64_t qId = taosHton64(pHead->qid); if (qId <= 0) { - tError("conn %p recv release, but invalid qid:%" PRId64 "", pConn, qId); + tError("conn %p recv release, but invalid sid:%" PRId64 "", pConn, qId); code = TSDB_CODE_RPC_NO_STATE; } else { void* p = taosHashGet(pConn->pQTable, &qId, sizeof(qId)); if (p == NULL) { code = TSDB_CODE_RPC_NO_STATE; - tTrace("conn %p recv release, and releady release by server qid:%" PRId64 "", pConn, qId); + tTrace("conn %p recv release, and releady release by server sid:%" PRId64 "", pConn, qId); } else { SSvrRegArg* arg = p; (pInst->cfp)(pInst->parent, &(arg->msg), NULL); - tTrace("conn %p recv release, notify server app, qid:%" PRId64 "", pConn, qId); + tTrace("conn %p recv release, notify server app, sid:%" PRId64 "", pConn, qId); code = taosHashRemove(pConn->pQTable, &qId, sizeof(qId)); if (code != 0) { - tDebug("conn %p failed to remove qid:%" PRId64 "", pConn, qId); + tDebug("conn %p failed to remove sid:%" PRId64 "", pConn, qId); } - tTrace("conn %p clear state,qid:%" PRId64 "", pConn, qId); + tTrace("conn %p clear state,sid:%" PRId64 "", pConn, qId); } } @@ -680,7 +680,7 @@ void uvOnSendCb(uv_write_t* req, int status) { SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); STraceId* trace = &smsg->msg.info.traceId; - tGDebug("%s conn %p msg already send out, seqNum:%" PRId64 ", qid:%" PRId64 "", transLabel(conn->pInst), conn, + tGDebug("%s conn %p msg already send out, seqNum:%" PRId64 ", sid:%" PRId64 "", transLabel(conn->pInst), conn, smsg->msg.info.seqNum, smsg->msg.info.qId); destroySmsg(smsg); } @@ -691,7 +691,7 @@ void uvOnSendCb(uv_write_t* req, int status) { SSvrRespMsg* smsg = QUEUE_DATA(head, SSvrRespMsg, q); STraceId* trace = &smsg->msg.info.traceId; - tGDebug("%s conn %p failed to send, seqNum:%" PRId64 ", qid:%" PRId64 " since %s", transLabel(conn->pInst), conn, + tGDebug("%s conn %p failed to send, seqNum:%" PRId64 ", sid:%" PRId64 " since %s", transLabel(conn->pInst), conn, smsg->msg.info.seqNum, smsg->msg.info.qId, uv_err_name(status)); destroySmsg(smsg); } @@ -759,7 +759,7 @@ static int32_t uvPrepareSendData(SSvrRespMsg* smsg, uv_buf_t* wb) { } STraceId* trace = &pMsg->info.traceId; - tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d, seqNum:%" PRId64 ", qid:%" PRId64 "", transLabel(pInst), + tGDebug("%s conn %p %s is sent to %s, local info:%s, len:%d, seqNum:%" PRId64 ", sid:%" PRId64 "", transLabel(pInst), pConn, TMSG_INFO(pHead->msgType), pConn->dst, pConn->src, len, pMsg->info.seqNum, pMsg->info.qId); wb->base = (char*)pHead; @@ -865,13 +865,13 @@ int32_t uvMayHandleReleaseResp(SSvrRespMsg* pMsg) { if (pMsg->msg.msgType == TDMT_SCH_TASK_RELEASE && qid > 0) { SSvrRegArg* p = taosHashGet(pConn->pQTable, &qid, sizeof(qid)); if (p == NULL) { - tError("%s conn %p already release qid:%" PRId64 "", transLabel(pConn->pInst), pConn, qid); + tError("%s conn %p already release sid:%" PRId64 "", transLabel(pConn->pInst), pConn, qid); return TSDB_CODE_RPC_NO_STATE; } else { transFreeMsg(p->msg.pCont); code = taosHashRemove(pConn->pQTable, &qid, sizeof(qid)); if (code != 0) { - tError("%s conn %p failed to release qid:%" PRId64 " since %s", transLabel(pConn->pInst), pConn, qid, + tError("%s conn %p failed to release sid:%" PRId64 " since %s", transLabel(pConn->pInst), pConn, qid, tstrerror(code)); } } @@ -1393,7 +1393,7 @@ void uvConnDestroyAllState(SSvrConn* p) { SSvrRegArg* arg = pIter; int64_t* qid = taosHashGetKey(pIter, NULL); (pInst->cfp)(pInst->parent, &(arg->msg), NULL); - tTrace("conn %p broken, notify server app, qid:%" PRId64 "", p, *qid); + tTrace("conn %p broken, notify server app, sid:%" PRId64 "", p, *qid); pIter = taosHashIterate(pQTable, pIter); } @@ -1698,7 +1698,7 @@ int32_t uvHandleStateReq(SSvrRespMsg* msg) { int32_t code = 0; SSvrConn* conn = msg->pConn; int64_t qid = msg->msg.info.qId; - tDebug("%s conn %p start to register brokenlink callback, qid:%" PRId64 "", transLabel(conn->pInst), conn, qid); + tDebug("%s conn %p start to register brokenlink callback, sid:%" PRId64 "", transLabel(conn->pInst), conn, qid); SSvrRegArg arg = {.notifyCount = 0, .init = 1, .msg = msg->msg}; SSvrRegArg* p = taosHashGet(conn->pQTable, &qid, sizeof(qid)); @@ -1875,7 +1875,7 @@ int32_t transReleaseSrvHandle(void* handle) { m->msg = tmsg; m->type = Normal; - tDebug("%s conn %p start to send %s, qid:%" PRId64 "", transLabel(pThrd->pInst), exh->handle, TMSG_INFO(tmsg.msgType), + tDebug("%s conn %p start to send %s, sid:%" PRId64 "", transLabel(pThrd->pInst), exh->handle, TMSG_INFO(tmsg.msgType), qId); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); From 3ab4726651c531ef2b6900a2ab6521d55d26582d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 1 Oct 2024 10:17:47 +0800 Subject: [PATCH 174/240] add config --- source/libs/transport/src/transCli.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 59104d6908..71715c0523 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3616,7 +3616,8 @@ static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { int32_t stateNum = taosHashGetSize(pConn->pQTable); int32_t totalReqs = reqsNum + reqsSentOut; - if (stateNum >= pInst->shareConnLimit || totalReqs >= pInst->shareConnLimit) { + if (((totalReqs >= pInst->shareConnLimit / 2) && (stateNum >= pInst->shareConnLimit)) || + totalReqs >= pInst->shareConnLimit) { if (pConn->list == NULL && pConn->dstAddr != NULL) { pConn->list = taosHashGet((SHashObj*)pThrd->pool, pConn->dstAddr, strlen(pConn->dstAddr)); if (pConn->list != NULL) { From fd6e1c5aabb15725c9f0f42887d93fe4cd7f7cdb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 1 Oct 2024 12:09:28 +0800 Subject: [PATCH 175/240] add config --- source/libs/transport/src/transCli.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 71715c0523..7bda574ff6 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1832,7 +1832,8 @@ int32_t cliHandleState_mayUpdateState(SCliConn* pConn, SCliReq* pReq) { SReqState state = {.conn = pConn, .arg = NULL}; code = taosHashPut(pThrd->pIdConnTable, &qid, sizeof(qid), &state, sizeof(state)); if (code != 0) { - tDebug("%s conn %p failed to statue, sid:%" PRId64 "", transLabel(pThrd->pInst), pConn, qid); + tDebug("%s conn %p failed to statue, sid:%" PRId64 " since %s", transLabel(pThrd->pInst), pConn, qid, + tstrerror(code)); } else { tDebug("%s conn %p succ to add statue, sid:%" PRId64 " (1)", transLabel(pThrd->pInst), pConn, qid); } @@ -1854,9 +1855,7 @@ void cliHandleBatchReq(SCliThrd* pThrd, SCliReq* pReq) { } else if (code == TSDB_CODE_RPC_STATE_DROPED) { TAOS_CHECK_GOTO(code, &lino, _exception); return; - } - - if (code == TSDB_CODE_RPC_NO_STATE || code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + } else if (code == TSDB_CODE_RPC_NO_STATE || code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { char addr[TSDB_FQDN_LEN + 64] = {0}; char* ip = EPSET_GET_INUSE_IP(pReq->ctx->epSet); int32_t port = EPSET_GET_INUSE_PORT(pReq->ctx->epSet); From 9d31855ccf820493f6820a22d7cf26e5f4ea2782 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 6 Oct 2024 09:49:56 +0800 Subject: [PATCH 176/240] add config --- source/libs/transport/src/transCli.c | 60 +++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 7bda574ff6..050069d6ea 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -107,6 +107,10 @@ typedef struct SCliConn { int32_t readerStart; queue wq; // uv_write_t queue + + queue batchSendq; + int8_t inThreadSendq; + } SCliConn; typedef struct { @@ -126,6 +130,7 @@ typedef struct SCliReq { int64_t seq; int32_t sent; //(0: no send, 1: alread sent) STransMsg msg; + int8_t inRetry; } SCliReq; @@ -164,6 +169,7 @@ typedef struct SCliThrd { SHashObj* pIdConnTable; // SArray* pQIdBuf; // tmp buf to avoid alloc buf; + queue batchSendSet; } SCliThrd; typedef struct SCliObj { @@ -192,7 +198,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn); static void cliBatchSendCb(uv_write_t* req, int status); void cliBatchSendImpl(SCliConn* pConn); -static int32_t cliBatchSend(SCliConn* conn); +static int32_t cliBatchSend(SCliConn* conn, int8_t direct); void cliConnCheckTimoutMsg(SCliConn* conn); bool cliConnRmReleaseReq(SCliConn* conn, STransMsgHead* pHead); // register conn timer @@ -1039,6 +1045,8 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int TAOS_CHECK_GOTO(initWQ(&conn->wq), NULL, _failed); + QUEUE_INIT(&conn->batchSendq); + conn->stream->data = conn; conn->connReq.data = conn; @@ -1278,7 +1286,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { } if (!cliMayRecycleConn(conn)) { - code = cliBatchSend(conn); + code = cliBatchSend(conn, 1); if (code != 0) { tDebug("%s conn %p failed to send msg since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); TAOS_UNUSED(transUnrefCliHandle(conn)); @@ -1307,7 +1315,7 @@ bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msg pConn->userInited = 1; return true; } -int32_t cliBatchSend(SCliConn* pConn) { +int32_t cliBatchSend(SCliConn* pConn, int8_t direct) { int32_t code = 0; SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; @@ -1319,6 +1327,17 @@ int32_t cliBatchSend(SCliConn* pConn) { if (pConn->connnected != 1) { return 0; } + + if (!direct) { + if (pConn->inThreadSendq) { + return 0; + } + QUEUE_PUSH(&pThrd->batchSendSet, &pConn->batchSendq); + pConn->inThreadSendq = 1; + tDebug("%s conn %p batch send later", pInst->label, pConn); + return 0; + } + int32_t size = transQueueSize(&pConn->reqsToSend); int32_t totalLen = 0; @@ -1420,7 +1439,20 @@ int32_t cliBatchSend(SCliConn* pConn) { int32_t cliSendReq(SCliConn* pConn, SCliReq* pCliMsg) { transQueuePush(&pConn->reqsToSend, &pCliMsg->q); - return cliBatchSend(pConn); + return cliBatchSend(pConn, pCliMsg->inRetry); +} +int32_t cliSendReqPrepare(SCliConn* pConn, SCliReq* pCliMsg) { + transQueuePush(&pConn->reqsToSend, &pCliMsg->q); + + if (pConn->broken) { + return 0; + } + + if (pConn->connnected != 1) { + return 0; + } + // return cliBatchSend(pConn); + return 0; } static void cliDestroyBatch(SCliBatch* pBatch) { @@ -1577,7 +1609,7 @@ void cliConnCb(uv_connect_t* req, int status) { } tTrace("%s conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn); - code = cliBatchSend(pConn); + code = cliBatchSend(pConn, 1); if (code != 0) { tDebug("%s conn %p failed to get sock info since %s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); TAOS_UNUSED(transUnrefCliHandle(pConn)); @@ -1906,13 +1938,13 @@ void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq) { return cliHandleBatchReq(pTh static void cliDoReq(queue* wq, SCliThrd* pThrd) { int count = 0; + QUEUE_INIT(&pThrd->batchSendSet); while (!QUEUE_IS_EMPTY(wq)) { queue* h = QUEUE_HEAD(wq); QUEUE_REMOVE(h); SCliReq* pReq = QUEUE_DATA(h, SCliReq, q); - if (pReq->type == Quit) { pThrd->stopMsg = pReq; continue; @@ -1920,6 +1952,17 @@ static void cliDoReq(queue* wq, SCliThrd* pThrd) { (*cliAsyncHandle[pReq->type])(pThrd, pReq); count++; } + + while (!QUEUE_IS_EMPTY(&pThrd->batchSendSet)) { + queue* el = QUEUE_HEAD(&pThrd->batchSendSet); + QUEUE_REMOVE(el); + + SCliConn* conn = QUEUE_DATA(el, SCliConn, batchSendq); + conn->inThreadSendq = 0; + QUEUE_INIT(&conn->batchSendq); + cliBatchSend(conn, 1); + } + QUEUE_INIT(&pThrd->batchSendSet); if (count >= 2) { tTrace("cli process batch size:%d", count); } @@ -2467,6 +2510,11 @@ FORCE_INLINE int cliRBChoseIdx(STrans* pInst) { } static FORCE_INLINE void doDelayTask(void* param) { STaskArg* arg = param; + + if (arg && arg->param1) { + SCliReq* pReq = arg->param1; + pReq->inRetry = 1; + } cliHandleReq((SCliThrd*)arg->param2, (SCliReq*)arg->param1); taosMemoryFree(arg); } From 71aca38fe5a4e0e6a2be104c550409c8ec880a0f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 6 Oct 2024 09:58:22 +0800 Subject: [PATCH 177/240] add config --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 050069d6ea..e71834e99a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -565,10 +565,10 @@ int32_t cliHandleState_mayCreateAhandle(SCliConn* conn, STransMsgHead* pHead, ST } STransCtx* pCtx = taosHashGet(conn->pQTable, &qId, sizeof(qId)); - pCtx->st = taosGetTimestampUs(); if (pCtx == 0) { return TSDB_CODE_RPC_NO_STATE; } + pCtx->st = taosGetTimestampUs(); STraceId* trace = &pHead->traceId; pResp->info.ahandle = transCtxDumpVal(pCtx, pHead->msgType); tGDebug("%s conn %p %s received from %s, local info:%s, sid:%" PRId64 ", create ahandle %p by %s", From 93257ba369fe61672ed510ee830fb827a1ebd1f8 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 6 Oct 2024 11:07:16 +0800 Subject: [PATCH 178/240] add config --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e71834e99a..1fab76a73e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1960,7 +1960,7 @@ static void cliDoReq(queue* wq, SCliThrd* pThrd) { SCliConn* conn = QUEUE_DATA(el, SCliConn, batchSendq); conn->inThreadSendq = 0; QUEUE_INIT(&conn->batchSendq); - cliBatchSend(conn, 1); + TAOS_UNUSED(cliBatchSend(conn, 1)); } QUEUE_INIT(&pThrd->batchSendSet); if (count >= 2) { From 16c6a5400b315c554cde8f2a7403f2355bdbe75d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 6 Oct 2024 17:08:18 +0800 Subject: [PATCH 179/240] add config --- source/libs/transport/src/transCli.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1fab76a73e..1f0aa8f9f6 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1952,7 +1952,7 @@ static void cliDoReq(queue* wq, SCliThrd* pThrd) { (*cliAsyncHandle[pReq->type])(pThrd, pReq); count++; } - + int32_t code = 0; while (!QUEUE_IS_EMPTY(&pThrd->batchSendSet)) { queue* el = QUEUE_HEAD(&pThrd->batchSendSet); QUEUE_REMOVE(el); @@ -1960,7 +1960,11 @@ static void cliDoReq(queue* wq, SCliThrd* pThrd) { SCliConn* conn = QUEUE_DATA(el, SCliConn, batchSendq); conn->inThreadSendq = 0; QUEUE_INIT(&conn->batchSendq); - TAOS_UNUSED(cliBatchSend(conn, 1)); + code = cliBatchSend(conn, 1); + if (code != 0) { + tWarn("%s conn %p failed to send req since %s", pThrd->pInst->label, conn, tstrerror(code)); + TAOS_UNUSED(transUnrefCliHandle(conn)); + } } QUEUE_INIT(&pThrd->batchSendSet); if (count >= 2) { From 664d3a42bf283348ea88ffa73c33b36203d705da Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 8 Oct 2024 09:27:51 +0800 Subject: [PATCH 180/240] add config --- source/common/src/tglobal.c | 4 ++-- source/libs/transport/src/transCli.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 6087af8f65..b1a1fe633f 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -608,7 +608,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "randErrorScope", tsRandErrScope, 0, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); tsNumOfRpcThreads = tsNumOfCores / 2; - tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); + tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 1, TSDB_MAX_RPC_THREADS); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfRpcThreads", tsNumOfRpcThreads, 1, 1024, CFG_SCOPE_BOTH, CFG_DYN_NONE)); tsNumOfRpcSessions = TRANGE(tsNumOfRpcSessions, 100, 100000); @@ -880,7 +880,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem = cfgGetItem(pCfg, "numOfRpcThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS); + tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 1, TSDB_MAX_RPC_THREADS); pItem->i32 = tsNumOfRpcThreads; pItem->stype = stype; } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1f0aa8f9f6..56c6aeb0e3 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2286,7 +2286,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end); } - int32_t nSync = pInst->supportBatch ? 4 : 8; + int32_t nSync = 2; // pInst->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)); From 3d3bb9bd5e52dc84ce9f03757d2114f98f3c7ed6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 11:53:17 +0800 Subject: [PATCH 181/240] fix error config --- source/common/src/tglobal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index b1a1fe633f..33818d7aa9 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -617,8 +617,8 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 256); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "shareConnLimit", tsShareConnLimit, 1, 256, CFG_SCOPE_BOTH, CFG_DYN_NONE)); - tsReadTimeout = TRANGE(tsReadTimeout, 0, 24 * 3600); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "readTimeout", tsShareConnLimit, 0, 24 * 3600, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "readTimeout", tsReadTimeout, 64, 24 * 3600, CFG_SCOPE_BOTH, CFG_DYN_NONE)); tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 10000000); TAOS_CHECK_RETURN( @@ -901,8 +901,8 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem = cfgGetItem(pCfg, "readTimeout"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsShareConnLimit = TRANGE(tsShareConnLimit, 64, 24 * 3600); - pItem->i32 = tsShareConnLimit; + tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600); + pItem->i32 = tsReadTimeout; pItem->stype = stype; } From b0108e00f92bf3d7e30e74a859f55e313f9b1e53 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 11:55:05 +0800 Subject: [PATCH 182/240] add config --- source/common/src/tglobal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 33818d7aa9..1f1188c664 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1390,6 +1390,9 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "shareConnLimit"); tsShareConnLimit = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "readTimeout"); + tsReadTimeout = pItem->i32; + TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); tsTimeToGetAvailableConn = pItem->i32; From 7ee56005722ade23893419b9ca9dadc75fc2c600 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 13:57:22 +0800 Subject: [PATCH 183/240] add config --- source/libs/transport/src/transCli.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 56c6aeb0e3..4b5ece0d45 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1181,13 +1181,13 @@ static void notifyAndDestroyReq(SCliConn* pConn, SCliReq* pReq, int32_t code) { } } -static FORCE_INLINE void destroyReqInQueue(SCliConn* conn, queue* set) { +static FORCE_INLINE void destroyReqInQueue(SCliConn* conn, queue* set, int32_t code) { while (!QUEUE_IS_EMPTY(set)) { queue* el = QUEUE_HEAD(set); QUEUE_REMOVE(el); SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); - notifyAndDestroyReq(conn, pReq, 0); + notifyAndDestroyReq(conn, pReq, code); } } static FORCE_INLINE int32_t destroyAllReqs(SCliConn* conn) { @@ -1202,7 +1202,7 @@ static FORCE_INLINE int32_t destroyAllReqs(SCliConn* conn) { transQueueRemoveByFilter(&conn->reqsSentOut, filterAllReq, NULL, &set, -1); transQueueRemoveByFilter(&conn->reqsToSend, filterAllReq, NULL, &set, -1); - destroyReqInQueue(conn, &set); + destroyReqInQueue(conn, &set, 0); return 0; } static void cliHandleException(SCliConn* conn) { @@ -3654,7 +3654,7 @@ static int8_t cliConnRemoveTimeoutMsg(SCliConn* pConn) { return 0; } tDebug("%s conn %p do remove timeout msg", pInst->label, pConn); - destroyReqInQueue(pConn, &set); + destroyReqInQueue(pConn, &set, TSDB_CODE_RPC_TIMEOUT); return 1; } static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { From cf4a5cbde0a36395c71dd4a59d642ef2127909bb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 17:21:14 +0800 Subject: [PATCH 184/240] add config --- include/util/tdef.h | 2 +- source/util/src/tref.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/util/tdef.h b/include/util/tdef.h index 46c84ab26a..4dfc4f8dd2 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -500,7 +500,7 @@ typedef enum ELogicConditionType { #ifdef WINDOWS #define TSDB_MAX_RPC_THREADS 4 // windows pipe only support 4 connections. #else -#define TSDB_MAX_RPC_THREADS 50 +#define TSDB_MAX_RPC_THREADS 20 #endif #define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type diff --git a/source/util/src/tref.c b/source/util/src/tref.c index 9360bd8b0e..f3597b5586 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -19,7 +19,7 @@ #include "tlog.h" #include "tutil.h" -#define TSDB_REF_OBJECTS 50 +#define TSDB_REF_OBJECTS 100 #define TSDB_REF_STATE_EMPTY 0 #define TSDB_REF_STATE_ACTIVE 1 #define TSDB_REF_STATE_DELETED 2 @@ -56,7 +56,7 @@ static void taosLockList(int64_t *lockedBy); static void taosUnlockList(int64_t *lockedBy); static void taosIncRsetCount(SRefSet *pSet); static void taosDecRsetCount(SRefSet *pSet); -static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t* isReleased); +static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t *isReleased); int32_t taosOpenRef(int32_t max, RefFp fp) { SRefNode **nodeList; @@ -254,7 +254,9 @@ void *taosAcquireRef(int32_t rsetId, int64_t rid) { } int32_t taosReleaseRef(int32_t rsetId, int64_t rid) { return taosDecRefCount(rsetId, rid, 0, NULL); } -int32_t taosReleaseRefEx(int32_t rsetId, int64_t rid, int32_t* isReleased) { return taosDecRefCount(rsetId, rid, 0, isReleased); } +int32_t taosReleaseRefEx(int32_t rsetId, int64_t rid, int32_t *isReleased) { + return taosDecRefCount(rsetId, rid, 0, isReleased); +} // if rid is 0, return the first p in hash list, otherwise, return the next after current rid void *taosIterateRef(int32_t rsetId, int64_t rid) { @@ -387,7 +389,7 @@ int32_t taosListRef() { return num; } -static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t* isReleased) { +static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove, int32_t *isReleased) { int32_t hash; SRefSet *pSet; SRefNode *pNode; From 457994066089c7c83d0c22be6b55622630b80141 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 17:55:28 +0800 Subject: [PATCH 185/240] add config --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4b5ece0d45..4bb0ede629 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1929,7 +1929,7 @@ _exception: code = (pThrd->notifyExceptCb)(pThrd, pReq, &resp); if (code != 0) { - tGWarn("%s failed to notify user since %s", pInst->label, tstrerror(code)); + tWarn("%s failed to notify user since %s", pInst->label, tstrerror(code)); } return; } From 54bae9d592399fb3635a3b2dec74d81c37421e35 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 19:59:28 +0800 Subject: [PATCH 186/240] add config --- source/libs/transport/src/transCli.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4bb0ede629..938247766e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1102,7 +1102,6 @@ static void cliDestroy(uv_handle_t* handle) { if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) { return; } - SCliConn* conn = handle->data; SCliThrd* pThrd = conn->hostThrd; cliResetConnTimer(conn); @@ -1223,6 +1222,11 @@ static void cliHandleException(SCliConn* conn) { conn->list = NULL; } + if (conn->task != NULL) { + transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); + conn->task = NULL; + } + if (conn->registered) { int8_t ref = transGetRefCount(conn); if (ref == 0 && !uv_is_closing((uv_handle_t*)conn->stream)) { @@ -3667,8 +3671,7 @@ static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { int32_t stateNum = taosHashGetSize(pConn->pQTable); int32_t totalReqs = reqsNum + reqsSentOut; - if (((totalReqs >= pInst->shareConnLimit / 2) && (stateNum >= pInst->shareConnLimit)) || - totalReqs >= pInst->shareConnLimit) { + if (totalReqs >= pInst->shareConnLimit) { if (pConn->list == NULL && pConn->dstAddr != NULL) { pConn->list = taosHashGet((SHashObj*)pThrd->pool, pConn->dstAddr, strlen(pConn->dstAddr)); if (pConn->list != NULL) { From e58f667611fe6666d0f6b7b0af74b745df80ede4 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 20:11:21 +0800 Subject: [PATCH 187/240] add config --- source/libs/executor/src/exchangeoperator.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 767796977c..20b21acf5f 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -530,6 +530,11 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { int32_t index = pWrapper->sourceIndex; SSourceDataInfo* pSourceDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, index); + + int64_t* pRpcHandle = taosArrayGet(pExchangeInfo->pFetchRpcHandles, index); + asyncFreeConnById(pExchangeInfo->pTransporter, *pRpcHandle); + *pRpcHandle = -1; + if (!pSourceDataInfo) { return terrno; } From 1ba3178a85baf6b40def004813f6d43126b7aa18 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 20:11:56 +0800 Subject: [PATCH 188/240] add config --- source/libs/executor/src/exchangeoperator.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 20b21acf5f..3861262a6c 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -532,8 +532,10 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { SSourceDataInfo* pSourceDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, index); int64_t* pRpcHandle = taosArrayGet(pExchangeInfo->pFetchRpcHandles, index); - asyncFreeConnById(pExchangeInfo->pTransporter, *pRpcHandle); - *pRpcHandle = -1; + if (pRpcHandle != NULL) { + asyncFreeConnById(pExchangeInfo->pTransporter, *pRpcHandle); + *pRpcHandle = -1; + } if (!pSourceDataInfo) { return terrno; From d4e24280e38a9a4afb366f16d589dd63b44a01dd Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 9 Oct 2024 21:47:51 +0800 Subject: [PATCH 189/240] add config --- source/libs/transport/src/transCli.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 938247766e..f11b34461d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -422,14 +422,17 @@ void cliConnMayUpdateTimer(SCliConn* conn, int64_t timeout) { } void destroyCliConnQTable(SCliConn* conn) { - int32_t code = 0; - void* pIter = taosHashIterate(conn->pQTable, NULL); + SCliThrd* thrd = conn->hostThrd; + int32_t code = 0; + void* pIter = taosHashIterate(conn->pQTable, NULL); while (pIter != NULL) { int64_t* qid = taosHashGetKey(pIter, NULL); STransCtx* ctx = pIter; transCtxCleanup(ctx); pIter = taosHashIterate(conn->pQTable, pIter); + TAOS_UNUSED(taosHashRemove(thrd->pIdConnTable, qid, sizeof(*qid))); + transReleaseExHandle(transGetRefMgt(), *qid); transRemoveExHandle(transGetRefMgt(), *qid); } @@ -996,6 +999,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int char addr[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(addr, ip, port); + conn->hostThrd = pThrd; conn->dstAddr = taosStrdup(addr); conn->ipStr = taosStrdup(ip); conn->port = port; @@ -1003,7 +1007,6 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn, char* ip, int TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _failed); } - conn->hostThrd = pThrd; conn->status = ConnNormal; conn->broken = false; QUEUE_INIT(&conn->q); From 10de8311539b3bc2e9ee40bf46a2e074facbbb09 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 10 Oct 2024 08:47:26 +0800 Subject: [PATCH 190/240] add config --- source/libs/transport/src/transCli.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f11b34461d..3354a81628 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1230,6 +1230,11 @@ static void cliHandleException(SCliConn* conn) { conn->task = NULL; } + code = delConnFromHeapCache(pThrd->connHeapCache, conn); + if (code != 0) { + tError("%s conn %p failed to del conn from heapcach since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + } + if (conn->registered) { int8_t ref = transGetRefCount(conn); if (ref == 0 && !uv_is_closing((uv_handle_t*)conn->stream)) { From aba70c79e18e766528fec431b12288d5da5c8d62 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 10 Oct 2024 09:59:40 +0800 Subject: [PATCH 191/240] add config --- source/libs/transport/src/transCli.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3354a81628..b7e76cf42d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -2542,8 +2542,6 @@ static FORCE_INLINE void doCloseIdleConn(void* param) { int32_t ref = transUnrefCliHandle(conn); if (ref <= 0) { - conn->task = NULL; - taosMemoryFree(arg); return; } taosMemoryFree(arg); @@ -2964,8 +2962,10 @@ int32_t transUnrefCliHandle(void* handle) { if (handle == NULL) { return 0; } + int32_t ref = 0; SCliConn* conn = (SCliConn*)handle; - int32_t ref = conn->ref--; + conn->ref--; + ref = conn->ref; tTrace("%s conn %p ref:%d", CONN_GET_INST_LABEL(conn), conn, conn->ref); if (conn->ref == 0) { From 8e6a51bfe158171747c85715f32cf6fb4dcbcc8b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 10 Oct 2024 11:51:36 +0800 Subject: [PATCH 192/240] add config --- source/os/src/osSemaphore.c | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/source/os/src/osSemaphore.c b/source/os/src/osSemaphore.c index ea9e824947..82644f75d6 100644 --- a/source/os/src/osSemaphore.c +++ b/source/os/src/osSemaphore.c @@ -74,7 +74,7 @@ int32_t taosGetAppName(char* name, int32_t* len) { int32_t tsem_wait(tsem_t* sem) { DWORD ret = WaitForSingleObject(*sem, INFINITE); - if(ret == WAIT_OBJECT_0) { + if (ret == WAIT_OBJECT_0) { return 0; } else { return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); @@ -140,7 +140,7 @@ int32_t tsem_wait(tsem_t *psem) { int32_t tsem_timewait(tsem_t *psem, int64_t milis) { if (psem == NULL || *psem == NULL) return -1; dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC)); - if(dispatch_semaphore_wait(*psem, time) == 0) { + if (dispatch_semaphore_wait(*psem, time) == 0) { return 0; } else { return TSDB_CODE_TIMEOUT_ERROR; @@ -218,7 +218,7 @@ int32_t taosGetAppName(char* name, int32_t* len) { } else { ++end; } - + tstrncpy(name, end, TSDB_APP_NAME_LEN); if (len != NULL) { @@ -228,8 +228,8 @@ int32_t taosGetAppName(char* name, int32_t* len) { return 0; } -int32_t tsem_init(tsem_t *psem, int flags, unsigned int count) { - if(sem_init(psem, flags, count) == 0) { +int32_t tsem_init(tsem_t* psem, int flags, unsigned int count) { + if (sem_init(psem, flags, count) == 0) { return 0; } else { return terrno = TAOS_SYSTEM_ERROR(errno); @@ -251,9 +251,9 @@ int32_t tsem_timewait(tsem_t* sem, int64_t ms) { ts.tv_nsec %= 1000000000; while ((ret = sem_timedwait(sem, &ts)) == -1) { - if(errno == EINTR) { + if (errno == EINTR) { continue; - } else if(errno == ETIMEDOUT) { + } else if (errno == ETIMEDOUT) { return TSDB_CODE_TIMEOUT_ERROR; } else { terrno = TAOS_SYSTEM_ERROR(errno); @@ -274,27 +274,27 @@ int32_t tsem_wait(tsem_t* sem) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - + return ret; } int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { int ret = taosThreadMutexInit(&sem->mutex, NULL); if (ret != 0) return ret; - + ret = taosThreadCondAttrInit(&sem->attr); if (ret != 0) { (void)taosThreadMutexDestroy(&sem->mutex); return ret; } - + ret = taosThreadCondAttrSetclock(&sem->attr, CLOCK_MONOTONIC); if (ret != 0) { (void)taosThreadMutexDestroy(&sem->mutex); (void)taosThreadCondAttrDestroy(&sem->attr); return ret; } - + ret = taosThreadCondInit(&sem->cond, &sem->attr); if (ret != 0) { (void)taosThreadMutexDestroy(&sem->mutex); @@ -303,7 +303,7 @@ int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { } sem->count = value; - + return 0; } @@ -315,7 +315,7 @@ int32_t tsem_post(tsem_t* psem) { } } -int32_t tsem_destroy(tsem_t *sem) { +int32_t tsem_destroy(tsem_t* sem) { if (sem_destroy(sem) == 0) { return 0; } else { @@ -323,7 +323,7 @@ int32_t tsem_destroy(tsem_t *sem) { } } -int tsem2_post(tsem2_t *sem) { +int tsem2_post(tsem2_t* sem) { int32_t code = taosThreadMutexLock(&sem->mutex); if (code) { return code; @@ -347,7 +347,7 @@ int tsem2_destroy(tsem2_t* sem) { (void)taosThreadMutexDestroy(&sem->mutex); (void)taosThreadCondDestroy(&sem->cond); (void)taosThreadCondAttrDestroy(&sem->attr); - + return 0; } @@ -367,7 +367,7 @@ int32_t tsem2_wait(tsem2_t* sem) { } } sem->count--; - + code = taosThreadMutexUnlock(&sem->mutex); if (code) { return code; @@ -383,7 +383,7 @@ int32_t tsem2_timewait(tsem2_t* sem, int64_t ms) { if (ret) { return ret; } - + if (sem->count <= 0) { struct timespec ts = {0}; if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) { @@ -402,17 +402,17 @@ int32_t tsem2_timewait(tsem2_t* sem, int64_t ms) { ret = taosThreadCondTimedWait(&sem->cond, &sem->mutex, &ts); if (ret != 0) { (void)taosThreadMutexUnlock(&sem->mutex); - if (errno == ETIMEDOUT) { + if (ret == ETIMEDOUT) { return TSDB_CODE_TIMEOUT_ERROR; } else { - return TAOS_SYSTEM_ERROR(errno); + return TAOS_SYSTEM_ERROR(ret); } } } } sem->count--; - + ret = taosThreadMutexUnlock(&sem->mutex); return ret; } From 142ded06c6bd5fd4a4ec7a50a7fc410ea8822c33 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 10 Oct 2024 14:40:25 +0800 Subject: [PATCH 193/240] add config --- source/libs/transport/src/transCli.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b7e76cf42d..0e11efaf45 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -894,7 +894,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->heapMissHit = 0; - if (conn->list->size >= 10) { + if (conn->list->size >= 2) { STaskArg* arg = taosMemoryCalloc(1, sizeof(STaskArg)); if (arg == NULL) return; arg->param1 = conn; @@ -2539,12 +2539,13 @@ static FORCE_INLINE void doCloseIdleConn(void* param) { STaskArg* arg = param; SCliConn* conn = arg->param1; tDebug("%s conn %p idle, close it", CONN_GET_INST_LABEL(conn), conn); + conn->task = NULL; + taosMemoryFree(arg); int32_t ref = transUnrefCliHandle(conn); if (ref <= 0) { return; } - taosMemoryFree(arg); } static FORCE_INLINE void cliPerfLog_schedMsg(SCliReq* pReq, char* label) { int32_t code = 0; From 17faedcee8dbbf10b8bba56fcaad2dbab76ba625 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 10 Oct 2024 15:24:00 +0800 Subject: [PATCH 194/240] add time out --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 0e11efaf45..9c8c8fb277 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -837,7 +837,7 @@ static int32_t cliGetConnFromPool(SCliThrd* pThrd, const char* key, SCliConn** p return TSDB_CODE_RPC_NETWORK_BUSY; } - queue* h = QUEUE_TAIL(&plist->conns); + queue* h = QUEUE_HEAD(&plist->conns); plist->size -= 1; QUEUE_REMOVE(h); @@ -894,7 +894,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->heapMissHit = 0; - if (conn->list->size >= 2) { + if (conn->list->size >= 5) { STaskArg* arg = taosMemoryCalloc(1, sizeof(STaskArg)); if (arg == NULL) return; arg->param1 = conn; From a1a421b41b40cfa0a8d8e15dd2c0a10a55f0300e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 14:35:46 +0800 Subject: [PATCH 195/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 26 +++++++++++++ source/util/test/CMakeLists.txt | 9 ++++- source/util/test/heapTest.cpp | 55 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 source/util/test/heapTest.cpp diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index b9bec12d14..4426eb0d44 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -282,6 +282,7 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); +static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); // thread obj static int32_t createThrdObj(void* trans, SCliThrd** pThrd); @@ -322,6 +323,7 @@ void transHeapDestroy(SHeap* heap); int32_t transHeapGet(SHeap* heap, SCliConn** p); int32_t transHeapInsert(SHeap* heap, SCliConn* p); int32_t transHeapDelete(SHeap* heap, SCliConn* p); +int32_t transHeapBalance(SHeap* heap, SCliConn* p); #define CLI_RELEASE_UV(loop) \ do { \ @@ -471,6 +473,11 @@ int32_t cliGetReqBySeq(SCliConn* conn, int64_t seq, int32_t msgType, SCliReq** p int8_t cliMayRecycleConn(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; + + code = balanceConnHeapCache(pThrd->connHeapCache, conn); + if (code != 0) { + tDebug("%s conn %p failed to balance heap cache", CONN_GET_INST_LABEL(conn), conn); + } if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && taosHashGetSize(conn->pQTable) == 0) { code = delConnFromHeapCache(pThrd->connHeapCache, conn); @@ -3780,6 +3787,13 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { } return code; } + +static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { + if (pConn->heap != NULL) { + return transHeapBalance(pConn->heap, pConn); + } + return 0; +} // conn heap int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { SCliConn* args1 = container_of(a, SCliConn, node); @@ -3850,3 +3864,15 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { } return 0; } + +int32_t transHeapBalance(SHeap* heap, SCliConn* p) { + if (p->inHeap == 0) { + return 0; + } + if (heap && heap->heap && heap->heap->nelts >= 64) { + tDebug("conn %p heap busy,heap size:%d", heap->heap->nelts); + } + heapRemove(heap->heap, &p->node); + heapInsert(heap->heap, &p->node); + return 0; +} diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index 0d8774ba41..e9b54934a3 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -126,6 +126,13 @@ add_test( COMMAND regexTest ) +add_executable(heapTest "heapTest.cpp") +target_link_libraries(heapTest os util gtest_main ) +add_test( + NAME heapTest + COMMAND heapTest +) + #add_executable(decompressTest "decompressTest.cpp") #target_link_libraries(decompressTest os util common gtest_main) #add_test( @@ -147,4 +154,4 @@ if (${TD_LINUX}) add_custom_command(TARGET terrorTest POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ERR_TBL_FILE} $ ) -endif () \ No newline at end of file +endif () diff --git a/source/util/test/heapTest.cpp b/source/util/test/heapTest.cpp new file mode 100644 index 0000000000..51eeb26ed3 --- /dev/null +++ b/source/util/test/heapTest.cpp @@ -0,0 +1,55 @@ +#include + +#include "taoserror.h" +#include "theap.h" + +using namespace std; + +typedef struct TNode { + int32_t data; + HeapNode node; +} TNodeMem; + +#define container_of(ptr, type, member) ((type*)((char*)(ptr)-offsetof(type, member))) +int32_t heapCompare(const HeapNode* a, const HeapNode* b) { + TNodeMem *ta = container_of(a, TNodeMem, node); + TNodeMem *tb = container_of(b, TNodeMem, node); + if (ta->data > tb->data) { + return 0; + } + return 1; +} + +TEST(TD_UTIL_HEAP_TEST, heapTest) { + Heap* heap = heapCreate(heapCompare); + ASSERT_TRUE(heap != NULL); + ASSERT_EQ(0, heapSize(heap)); + + + int32_t limit = 10; + + TNodeMem **pArr = (TNodeMem **)taosMemoryCalloc(100, sizeof(TNodeMem *)); + for (int i = 0; i < 100; i++) { + TNodeMem *a = (TNodeMem *)taosMemoryCalloc(1, sizeof(TNodeMem)); + a->data = i%limit; + + heapInsert(heap, &a->node); + + pArr[i] = a; + TNodeMem *b = (TNodeMem *)taosMemoryCalloc(1, sizeof(TNodeMem)); + b->data = (limit - i)%limit; + heapInsert(heap, &b->node); + } + for (int i = 98; i < 100; i++) { + TNodeMem *p = pArr[i]; + p->data = -100000; + } + HeapNode *node = heapMin(heap); + while (node != NULL) { + TNodeMem *data = container_of(node, TNodeMem, node); + heapRemove(heap, node); + printf("%d\t", data->data); + node = heapMin(heap); + } + heapDestroy(heap); +} From ecfe407f32f01426ab7d9fff5f31aacb11c2edd5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 14:38:29 +0800 Subject: [PATCH 196/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4426eb0d44..ee7fe3e105 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3866,10 +3866,10 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { } int32_t transHeapBalance(SHeap* heap, SCliConn* p) { - if (p->inHeap == 0) { + if (p->inHeap == 0 && heap == NULL || heap->heap == NULL) { return 0; } - if (heap && heap->heap && heap->heap->nelts >= 64) { + if (heap->heap->nelts >= 64) { tDebug("conn %p heap busy,heap size:%d", heap->heap->nelts); } heapRemove(heap->heap, &p->node); From f2ebc9236c1311505a407ae443d77aa1a77be7d8 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 14:38:57 +0800 Subject: [PATCH 197/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index ee7fe3e105..a51d75a108 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3869,8 +3869,8 @@ int32_t transHeapBalance(SHeap* heap, SCliConn* p) { if (p->inHeap == 0 && heap == NULL || heap->heap == NULL) { return 0; } - if (heap->heap->nelts >= 64) { - tDebug("conn %p heap busy,heap size:%d", heap->heap->nelts); + if (heap->heap->nelts >= 32) { + tTrace("conn %p heap busy,heap size:%d", heap->heap->nelts); } heapRemove(heap->heap, &p->node); heapInsert(heap->heap, &p->node); From 514b04a6bd71a8215fdd402091b5e4dfa397aa9d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 16:43:56 +0800 Subject: [PATCH 198/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/executor/src/exchangeoperator.c | 2 +- source/libs/transport/src/transCli.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 3861262a6c..6e4f288246 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -226,7 +226,7 @@ static SSDataBlock* doLoadRemoteDataImpl(SOperatorInfo* pOperator) { concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); } if (TSDB_CODE_SUCCESS != pOperator->pTaskInfo->code) { - qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(pOperator->pTaskInfo->code)); T_LONG_JMP(pTaskInfo->env, pOperator->pTaskInfo->code); } if (taosArrayGetSize(pExchangeInfo->pResultBlockList) == 0) { diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a51d75a108..a17322db2d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -474,10 +474,10 @@ int8_t cliMayRecycleConn(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; - code = balanceConnHeapCache(pThrd->connHeapCache, conn); - if (code != 0) { - tDebug("%s conn %p failed to balance heap cache", CONN_GET_INST_LABEL(conn), conn); - } + // code = balanceConnHeapCache(pThrd->connHeapCache, conn); + // if (code != 0) { + // tDebug("%s conn %p failed to balance heap cache", CONN_GET_INST_LABEL(conn), conn); + // } if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && taosHashGetSize(conn->pQTable) == 0) { code = delConnFromHeapCache(pThrd->connHeapCache, conn); @@ -3741,6 +3741,9 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; } else { + if (pHeap->heap->nelts >= 16) { + balanceConnHeapCache(pConnHeapCache, pConn); + } if (shouldSWitchToOtherConn(pConn, key)) { logConnMissHit(pConn); return NULL; @@ -3789,7 +3792,7 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { } static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { - if (pConn->heap != NULL) { + if (pConn->heap != NULL && pConn->inHeap != 0) { return transHeapBalance(pConn->heap, pConn); } return 0; From 5eaa6f34fe0f3c55a1eb0b513219b6c08feb6811 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 16:46:05 +0800 Subject: [PATCH 199/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a17322db2d..7323e99f42 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3741,10 +3741,10 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; } else { - if (pHeap->heap->nelts >= 16) { - balanceConnHeapCache(pConnHeapCache, pConn); - } if (shouldSWitchToOtherConn(pConn, key)) { + if (pHeap->heap->nelts >= 16) { + balanceConnHeapCache(pConnHeapCache, pConn); + } logConnMissHit(pConn); return NULL; } From defe4bf6a8b01f0e79316cbe98af118fc4cc5bd7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 17:08:10 +0800 Subject: [PATCH 200/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 7323e99f42..223ed0349c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3873,7 +3873,7 @@ int32_t transHeapBalance(SHeap* heap, SCliConn* p) { return 0; } if (heap->heap->nelts >= 32) { - tTrace("conn %p heap busy,heap size:%d", heap->heap->nelts); + tTrace("conn %p heap busy,heap size:%d", p, heap->heap->nelts); } heapRemove(heap->heap, &p->node); heapInsert(heap->heap, &p->node); From 3b0d3427930ce911f68c1a7433afc17aa329bf29 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 17:24:38 +0800 Subject: [PATCH 201/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 223ed0349c..a48b29e34d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -315,6 +315,7 @@ typedef struct { // void* p; Heap* heap; int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b); + int64_t lastUpdateTs; } SHeap; int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); @@ -3742,7 +3743,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } else { if (shouldSWitchToOtherConn(pConn, key)) { - if (pHeap->heap->nelts >= 16) { + if (pHeap->heap->nelts >= 8) { balanceConnHeapCache(pConnHeapCache, pConn); } logConnMissHit(pConn); @@ -3793,7 +3794,14 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { if (pConn->heap != NULL && pConn->inHeap != 0) { - return transHeapBalance(pConn->heap, pConn); + SHeap* heap = pConn->heap; + tTrace("conn %p'heap have too many conn %d, should do balance", pConn, heap->heap->nelts); + int64_t now = taosGetTimestampMs(); + if (((now - heap->lastUpdateTs) / 1000) > 30) { + heap->lastUpdateTs = now; + tTrace("conn %p'heap have too many conn %d, do balance", pConn, heap->heap->nelts); + return transHeapBalance(pConn->heap, pConn); + } } return 0; } @@ -3872,9 +3880,6 @@ int32_t transHeapBalance(SHeap* heap, SCliConn* p) { if (p->inHeap == 0 && heap == NULL || heap->heap == NULL) { return 0; } - if (heap->heap->nelts >= 32) { - tTrace("conn %p heap busy,heap size:%d", p, heap->heap->nelts); - } heapRemove(heap->heap, &p->node); heapInsert(heap->heap, &p->node); return 0; From 2ca458fa30e42cd0bdb8c8078e15906b3ce82e16 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 17:30:26 +0800 Subject: [PATCH 202/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a48b29e34d..66d48319cc 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3743,8 +3743,9 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } else { if (shouldSWitchToOtherConn(pConn, key)) { - if (pHeap->heap->nelts >= 8) { - balanceConnHeapCache(pConnHeapCache, pConn); + code = balanceConnHeapCache(pConnHeapCache, pConn); + if (code != 0) { + tDebug("failed to balance conn heap cache for key:%s", key); } logConnMissHit(pConn); return NULL; From 731f9b3fb75de69474b95599b133788debf5b4f7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 17:32:11 +0800 Subject: [PATCH 203/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 66d48319cc..aed1e9339a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3796,11 +3796,11 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { if (pConn->heap != NULL && pConn->inHeap != 0) { SHeap* heap = pConn->heap; - tTrace("conn %p'heap have too many conn %d, should do balance", pConn, heap->heap->nelts); + tTrace("conn %p'heap may should do balance, numOfConn:%d", pConn, heap->heap->nelts); int64_t now = taosGetTimestampMs(); if (((now - heap->lastUpdateTs) / 1000) > 30) { heap->lastUpdateTs = now; - tTrace("conn %p'heap have too many conn %d, do balance", pConn, heap->heap->nelts); + tTrace("conn %p'heap do balance, numOfConn:%d", pConn, heap->heap->nelts); return transHeapBalance(pConn->heap, pConn); } } From f27ff536eb644ecaaac72933331c033278b8c627 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 18:11:45 +0800 Subject: [PATCH 204/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index aed1e9339a..53dd5291cb 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -316,6 +316,7 @@ typedef struct { Heap* heap; int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b); int64_t lastUpdateTs; + int64_t lastConnFailTs; } SHeap; int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); @@ -325,6 +326,7 @@ int32_t transHeapGet(SHeap* heap, SCliConn** p); int32_t transHeapInsert(SHeap* heap, SCliConn* p); int32_t transHeapDelete(SHeap* heap, SCliConn* p); int32_t transHeapBalance(SHeap* heap, SCliConn* p); +int32_t transHeapUpdateFailTs(SHeap* heap, SCliConn* p); #define CLI_RELEASE_UV(loop) \ do { \ @@ -978,7 +980,9 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) code = cliHandleState_mayUpdateState(pConn, pReq); code = addConnToHeapCache(pThrd->connHeapCache, pConn); - if (code != 0) { + // code = 0, succ + // code = 0, + if (code != 0 && code != TSDB_CODE_RPC_NETWORK_UNAVAIL) { TAOS_CHECK_GOTO(code, NULL, _exception); } transQueuePush(&pConn->reqsToSend, &pReq->q); @@ -1527,6 +1531,7 @@ static int32_t cliDoConn(SCliThrd* pThrd, SCliConn* conn) { ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { tError("failed connect to %s since %s", conn->dstAddr, uv_err_name(ret)); + TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, &lino, _exception1); } @@ -3767,6 +3772,12 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { if (code != 0) { return code; } + if (pConn->connnected == 0) { + int64_t now = taosGetTimestampMs(); + if (now - p->lastConnFailTs < 3000) { + return TSDB_CODE_RPC_NETWORK_UNAVAIL; + } + } } code = transHeapInsert(p, pConn); @@ -3860,6 +3871,9 @@ int32_t transHeapInsert(SHeap* heap, SCliConn* p) { } int32_t transHeapDelete(SHeap* heap, SCliConn* p) { // impl later + if (p->connnected == 0) { + transHeapUpdateFailTs(heap, p); + } if (p->inHeap == 0) { tDebug("failed to del conn %p since not in heap", p); return 0; @@ -3877,6 +3891,11 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { return 0; } +int32_t transHeapUpdateFailTs(SHeap* heap, SCliConn* p) { + heap->lastConnFailTs = taosGetTimestampMs(); + return 0; +} + int32_t transHeapBalance(SHeap* heap, SCliConn* p) { if (p->inHeap == 0 && heap == NULL || heap->heap == NULL) { return 0; From 1a5477f2b579b3139355078807ae2247a2ab9faf Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 11 Oct 2024 18:24:11 +0800 Subject: [PATCH 205/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 53dd5291cb..f9531db97b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -981,7 +981,7 @@ static int32_t cliCreateConn2(SCliThrd* pThrd, SCliReq* pReq, SCliConn** ppConn) code = addConnToHeapCache(pThrd->connHeapCache, pConn); // code = 0, succ - // code = 0, + // code = TSDB_CODE_RPC_NETWORK_UNAVALI, fail fast, and not insert into conn heap if (code != 0 && code != TSDB_CODE_RPC_NETWORK_UNAVAIL) { TAOS_CHECK_GOTO(code, NULL, _exception); } From 331235a82832bb0759dbfee6dbadb6a59357247f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 09:09:10 +0800 Subject: [PATCH 206/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f9531db97b..774bf1aeb2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -101,6 +101,7 @@ typedef struct SCliConn { void* heap; // point to req conn heap int32_t heapMissHit; + int64_t lastAddHeapTime; uv_buf_t* buf; int32_t bufSize; @@ -3866,6 +3867,7 @@ int32_t transHeapInsert(SHeap* heap, SCliConn* p) { heapInsert(heap->heap, &p->node); p->inHeap = 1; + p->lastAddHeapTime = taosGetTimestampMs(); p->heap = heap; return 0; } @@ -3877,7 +3879,14 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { if (p->inHeap == 0) { tDebug("failed to del conn %p since not in heap", p); return 0; + } else { + int64_t now = taosGetTimestampMs(); + if (now - p->lastAddHeapTime < 10000) { + tDebug("conn %p not added to heap frequently", p); + return 0; + } } + p->inHeap = 0; p->reqRefCnt--; if (p->reqRefCnt == 0) { From 437f9d64b4cca9cfebef5924d882b728f9b1d02d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 09:25:26 +0800 Subject: [PATCH 207/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 774bf1aeb2..59412cb217 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3680,7 +3680,7 @@ static int8_t cliConnRemoveTimeoutMsg(SCliConn* pConn) { if (QUEUE_IS_EMPTY(&set)) { return 0; } - tDebug("%s conn %p do remove timeout msg", pInst->label, pConn); + tWarn("%s conn %p do remove timeout msg", pInst->label, pConn); destroyReqInQueue(pConn, &set, TSDB_CODE_RPC_TIMEOUT); return 1; } @@ -3698,13 +3698,13 @@ static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { if (pConn->list == NULL && pConn->dstAddr != NULL) { pConn->list = taosHashGet((SHashObj*)pThrd->pool, pConn->dstAddr, strlen(pConn->dstAddr)); if (pConn->list != NULL) { - tDebug("conn %p get list %p from pool for key:%s", pConn, pConn->list, key); + tTrace("conn %p get list %p from pool for key:%s", pConn, pConn->list, key); } } if (pConn->list && pConn->list->totaSize >= pInst->connLimitNum / 4) { tWarn("%s conn %p try to remove timeout msg since too many conn created", transLabel(pInst), pConn); if (cliConnRemoveTimeoutMsg(pConn)) { - tDebug("%s conn %p succ to remove timeout msg", transLabel(pInst), pConn); + tWarn("%s conn %p succ to remove timeout msg", transLabel(pInst), pConn); } return 1; } @@ -3740,18 +3740,18 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { SCliConn* pConn = NULL; code = getOrCreateHeap(pConnHeapCache, key, &pHeap); if (code != 0) { - tDebug("failed to get conn heap from cache for key:%s", key); + tTrace("failed to get conn heap from cache for key:%s", key); return NULL; } code = transHeapGet(pHeap, &pConn); if (code != 0) { - tDebug("failed to get conn from heap cache for key:%s", key); + tTrace("failed to get conn from heap cache for key:%s", key); return NULL; } else { if (shouldSWitchToOtherConn(pConn, key)) { code = balanceConnHeapCache(pConnHeapCache, pConn); if (code != 0) { - tDebug("failed to balance conn heap cache for key:%s", key); + tTrace("failed to balance conn heap cache for key:%s", key); } logConnMissHit(pConn); return NULL; @@ -3766,7 +3766,7 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { if (pConn->heap != NULL) { p = pConn->heap; - tDebug("conn %p add to heap cache for key:%s,status:%d, refCnt:%d, add direct", pConn, pConn->dstAddr, + tTrace("conn %p add to heap cache for key:%s,status:%d, refCnt:%d, add direct", pConn, pConn->dstAddr, pConn->inHeap, pConn->reqRefCnt); } else { code = getOrCreateHeap(pConnHeapCacahe, pConn->dstAddr, &p); @@ -3782,25 +3782,25 @@ static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) { } code = transHeapInsert(p, pConn); - tDebug("conn %p add to heap cache for key:%s,status:%d, refCnt:%d", pConn, pConn->dstAddr, pConn->inHeap, + tTrace("conn %p add to heap cache for key:%s,status:%d, refCnt:%d", pConn, pConn->dstAddr, pConn->inHeap, pConn->reqRefCnt); return code; } static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { if (pConn->heap != NULL) { - tDebug("conn %p delete from heap cache direct", pConn); + tTrace("conn %p try to delete from heap cache direct", pConn); return transHeapDelete(pConn->heap, pConn); } SHeap* p = taosHashGet(pConnHeapCache, pConn->dstAddr, strlen(pConn->dstAddr)); if (p == NULL) { - tDebug("failed to get heap cache for key:%s, no need to del", pConn->dstAddr); + tTrace("failed to get heap cache for key:%s, no need to del", pConn->dstAddr); return 0; } int32_t code = transHeapDelete(p, pConn); if (code != 0) { - tDebug("conn %p failed delete from heap cache since %s", pConn, tstrerror(code)); + tTrace("conn %p failed delete from heap cache since %s", pConn, tstrerror(code)); } return code; } @@ -3861,7 +3861,7 @@ int32_t transHeapInsert(SHeap* heap, SCliConn* p) { // impl later p->reqRefCnt++; if (p->inHeap == 1) { - tDebug("failed to insert conn %p since already in heap", p); + tTrace("failed to insert conn %p since already in heap", p); return TSDB_CODE_DUP_KEY; } @@ -3877,12 +3877,12 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { transHeapUpdateFailTs(heap, p); } if (p->inHeap == 0) { - tDebug("failed to del conn %p since not in heap", p); + tTrace("failed to del conn %p since not in heap", p); return 0; } else { int64_t now = taosGetTimestampMs(); if (now - p->lastAddHeapTime < 10000) { - tDebug("conn %p not added to heap frequently", p); + tTrace("conn %p not added/delete to heap frequently", p); return 0; } } @@ -3891,11 +3891,11 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { p->reqRefCnt--; if (p->reqRefCnt == 0) { heapRemove(heap->heap, &p->node); - tDebug("conn %p delete from heap", p); + tTrace("conn %p delete from heap", p); } else if (p->reqRefCnt < 0) { - tDebug("conn %p has %d reqs, not delete from heap,assert", p, p->reqRefCnt); + tTrace("conn %p has %d reqs, not delete from heap,assert", p, p->reqRefCnt); } else { - tDebug("conn %p has %d reqs, not delete from heap", p, p->reqRefCnt); + tTrace("conn %p has %d reqs, not delete from heap", p, p->reqRefCnt); } return 0; } From 8df6527287d562c244c60a45e0a2fa09f008ab35 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 10:01:59 +0800 Subject: [PATCH 208/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 59412cb217..e7bf94cd31 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -102,6 +102,7 @@ typedef struct SCliConn { void* heap; // point to req conn heap int32_t heapMissHit; int64_t lastAddHeapTime; + int8_t forceDelFromHeap; uv_buf_t* buf; int32_t bufSize; @@ -1129,6 +1130,7 @@ static void cliDestroy(uv_handle_t* handle) { tDebug("%s conn %p failed to all reqs since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); } + conn->forceDelFromHeap = 1; code = delConnFromHeapCache(pThrd->connHeapCache, conn); if (code != 0) { tDebug("%s conn %p failed to del conn from heapcach since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); @@ -1242,7 +1244,7 @@ static void cliHandleException(SCliConn* conn) { transDQCancel(((SCliThrd*)conn->hostThrd)->timeoutQueue, conn->task); conn->task = NULL; } - + conn->forceDelFromHeap = 1; code = delConnFromHeapCache(pThrd->connHeapCache, conn); if (code != 0) { tError("%s conn %p failed to del conn from heapcach since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); @@ -3881,7 +3883,7 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { return 0; } else { int64_t now = taosGetTimestampMs(); - if (now - p->lastAddHeapTime < 10000) { + if (p->forceDelFromHeap == 0 && now - p->lastAddHeapTime < 10000) { tTrace("conn %p not added/delete to heap frequently", p); return 0; } From bbecb9e7a98241f87bfbd2c8478a446cb5344e23 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 11:16:07 +0800 Subject: [PATCH 209/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index e7bf94cd31..8f64cbb691 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -479,14 +479,14 @@ int8_t cliMayRecycleConn(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; - // code = balanceConnHeapCache(pThrd->connHeapCache, conn); - // if (code != 0) { - // tDebug("%s conn %p failed to balance heap cache", CONN_GET_INST_LABEL(conn), conn); - // } if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && taosHashGetSize(conn->pQTable) == 0) { code = delConnFromHeapCache(pThrd->connHeapCache, conn); - if (code != 0) { + if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + tError("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, + tstrerror(code)); + return 0; + } else { tError("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); } @@ -3878,6 +3878,7 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { if (p->connnected == 0) { transHeapUpdateFailTs(heap, p); } + if (p->inHeap == 0) { tTrace("failed to del conn %p since not in heap", p); return 0; @@ -3885,7 +3886,7 @@ int32_t transHeapDelete(SHeap* heap, SCliConn* p) { int64_t now = taosGetTimestampMs(); if (p->forceDelFromHeap == 0 && now - p->lastAddHeapTime < 10000) { tTrace("conn %p not added/delete to heap frequently", p); - return 0; + return TSDB_CODE_RPC_ASYNC_IN_PROCESS; } } From a6b59ae4f5f2fc67ca499a8f1aa66a81b6785b8b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 11:16:51 +0800 Subject: [PATCH 210/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 8f64cbb691..258952a69f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -485,7 +485,7 @@ int8_t cliMayRecycleConn(SCliConn* conn) { if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { tError("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); - return 0; + return 1; } else { tError("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); From f0627eebbdcd54c33244858d02bed19c98d9dc3c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 11:18:00 +0800 Subject: [PATCH 211/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 258952a69f..ee1e4f7dae 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3750,6 +3750,7 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { tTrace("failed to get conn from heap cache for key:%s", key); return NULL; } else { + tTrace("conn %p get conn from heap cache for key:%s", pConn, key); if (shouldSWitchToOtherConn(pConn, key)) { code = balanceConnHeapCache(pConnHeapCache, pConn); if (code != 0) { From 01c362840f48c00486a0ab7a639ababf20d8dee2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 11:22:20 +0800 Subject: [PATCH 212/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index ee1e4f7dae..8906f18282 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -483,7 +483,7 @@ int8_t cliMayRecycleConn(SCliConn* conn) { taosHashGetSize(conn->pQTable) == 0) { code = delConnFromHeapCache(pThrd->connHeapCache, conn); if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { - tError("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, + tDebug("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); return 1; } else { From 5df93eab1744c192e38382387347b405427d481c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 11:54:04 +0800 Subject: [PATCH 213/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 8906f18282..9fa9285bfc 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -172,6 +172,7 @@ typedef struct SCliThrd { SArray* pQIdBuf; // tmp buf to avoid alloc buf; queue batchSendSet; + int8_t thrdInited; } SCliThrd; typedef struct SCliObj { @@ -2238,11 +2239,13 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, int err = taosThreadCreate(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd)); if (err != 0) { + destroyThrdObj(pThrd); code = TAOS_SYSTEM_ERROR(errno); TAOS_CHECK_GOTO(code, NULL, _err); } else { tDebug("success to create tranport-cli thread:%d", i); } + pThrd->thrdInited = 1; cli->pThreadObj[i] = pThrd; } return cli; @@ -2433,7 +2436,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { return; } - if (taosThreadJoin(pThrd->thread, NULL) != 0) { + if (pThrd->thrdInited && taosThreadJoin(pThrd->thread, NULL) != 0) { tTrace("failed to join thread since %s", tstrerror(terrno)); } From 4ad6addfb7b981211812418e9baa4f8f14337a15 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 13:44:19 +0800 Subject: [PATCH 214/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 9fa9285bfc..0b888e365d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -488,8 +488,10 @@ int8_t cliMayRecycleConn(SCliConn* conn) { tstrerror(code)); return 1; } else { - tError("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, - tstrerror(code)); + if (code != 0) { + tDebug("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, + tstrerror(code)); + } } addConnToPool(pThrd->pool, conn); return 1; From f8e955ca6199663e178378c69124eb24018b7897 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 16:31:31 +0800 Subject: [PATCH 215/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 0b888e365d..28fc936be5 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3816,11 +3816,11 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { if (pConn->heap != NULL && pConn->inHeap != 0) { SHeap* heap = pConn->heap; - tTrace("conn %p'heap may should do balance, numOfConn:%d", pConn, heap->heap->nelts); + tTrace("conn %p'heap may should do balance, numOfConn:%d", pConn, (int)(heap->heap->nelts)); int64_t now = taosGetTimestampMs(); if (((now - heap->lastUpdateTs) / 1000) > 30) { heap->lastUpdateTs = now; - tTrace("conn %p'heap do balance, numOfConn:%d", pConn, heap->heap->nelts); + tTrace("conn %p'heap do balance, numOfConn:%d", pConn, (int)(heap->heap->nelts)); return transHeapBalance(pConn->heap, pConn); } } From a0324f41a6442d185db8371ee369f42138733ef2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 16:45:55 +0800 Subject: [PATCH 216/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/executor/src/exchangeoperator.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 6e4f288246..9766a39803 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -533,7 +533,11 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { int64_t* pRpcHandle = taosArrayGet(pExchangeInfo->pFetchRpcHandles, index); if (pRpcHandle != NULL) { - asyncFreeConnById(pExchangeInfo->pTransporter, *pRpcHandle); + code = asyncFreeConnById(pExchangeInfo->pTransporter, *pRpcHandle); + if (code != 0) { + qError("failed to free rpc handle, code:%s, %p", tstrerror(code), pExchangeInfo); + code = 0; + } *pRpcHandle = -1; } From 380ffb32de068129243e10ca371746def0e4670f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 16:48:13 +0800 Subject: [PATCH 217/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 28fc936be5..106ab841c8 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3882,7 +3882,7 @@ int32_t transHeapInsert(SHeap* heap, SCliConn* p) { int32_t transHeapDelete(SHeap* heap, SCliConn* p) { // impl later if (p->connnected == 0) { - transHeapUpdateFailTs(heap, p); + TAOS_UNUSED(transHeapUpdateFailTs(heap, p)); } if (p->inHeap == 0) { From 51e393889761a5e742fca548ebf2a139d32bb49e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 18:52:44 +0800 Subject: [PATCH 218/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 106ab841c8..7f04512308 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3668,7 +3668,7 @@ static void cliConnRemoveTimeoutNoQidMsg(SCliConn* pConn, int64_t* st, queue* se SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; SListFilterArg arg = {.id = *st, .pInst = pInst}; - transQueueRemoveByFilter(&pConn->reqsToSend, filterTimeoutReq, st, &set, -1); + transQueueRemoveByFilter(&pConn->reqsToSend, filterTimeoutReq, &arg, &set, -1); return; } From ae770e1dd0ea38bbf7e4edc8694c9ec2ef944ef0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 12 Oct 2024 19:20:21 +0800 Subject: [PATCH 219/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/executor/src/exchangeoperator.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 9766a39803..d92652d288 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -533,10 +533,9 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { int64_t* pRpcHandle = taosArrayGet(pExchangeInfo->pFetchRpcHandles, index); if (pRpcHandle != NULL) { - code = asyncFreeConnById(pExchangeInfo->pTransporter, *pRpcHandle); - if (code != 0) { - qError("failed to free rpc handle, code:%s, %p", tstrerror(code), pExchangeInfo); - code = 0; + int32_t ret = asyncFreeConnById(pExchangeInfo->pTransporter, *pRpcHandle); + if (ret != 0) { + qError("failed to free rpc handle, code:%s, %p", tstrerror(ret), pExchangeInfo); } *pRpcHandle = -1; } From cc033c926021018620266345346039f020eb5ec5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 14 Oct 2024 18:02:59 +0800 Subject: [PATCH 220/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 7f04512308..1074f050fa 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3643,14 +3643,15 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) tstrerror(code)); break; } + tWarn("%s conn %p remove timeout msg sid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), pConn, *qid); } pIter = taosHashIterate(pConn->pQTable, pIter); } for (int32_t i = 0; i < taosArrayGetSize(pQIdBuf); i++) { int64_t* qid = taosArrayGet(pQIdBuf, i); - transQueueRemoveByFilter(&pConn->reqsSentOut, filterByQid, qid, &set, -1); - transQueueRemoveByFilter(&pConn->reqsToSend, filterByQid, qid, &set, -1); + transQueueRemoveByFilter(&pConn->reqsSentOut, filterByQid, qid, set, -1); + transQueueRemoveByFilter(&pConn->reqsToSend, filterByQid, qid, set, -1); STransCtx* p = taosHashGet(pConn->pQTable, qid, sizeof(*qid)); transCtxCleanup(p); @@ -3668,7 +3669,7 @@ static void cliConnRemoveTimeoutNoQidMsg(SCliConn* pConn, int64_t* st, queue* se SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; SListFilterArg arg = {.id = *st, .pInst = pInst}; - transQueueRemoveByFilter(&pConn->reqsToSend, filterTimeoutReq, &arg, &set, -1); + transQueueRemoveByFilter(&pConn->reqsToSend, filterTimeoutReq, &arg, set, -1); return; } From 9a480e0597cf9a869ff85e2a85dc6779b9b4fcbe Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 14 Oct 2024 19:19:01 +0800 Subject: [PATCH 221/240] reset timeout --- source/libs/transport/src/transCli.c | 65 +++++++++++++++------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1074f050fa..6797716c7b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -310,6 +310,7 @@ static FORCE_INLINE bool filterToDebug_timeoutMsg(void* key, void* arg); static FORCE_INLINE bool filterToRmTimoutReq(void* key, void* arg); static FORCE_INLINE bool filterTimeoutReq(void* key, void* arg); +static int8_t cliConnRemoveTimeoutMsg(SCliConn* pConn); typedef struct { void* p; HeapNode node; @@ -682,7 +683,7 @@ void cliHandleResp(SCliConn* conn) { } cliConnCheckTimoutMsg(conn); - cliConnMayUpdateTimer(conn, pInst->readTimeout); + cliConnMayUpdateTimer(conn, pInst->readTimeout * 1000); } void cliConnTimeout(uv_timer_t* handle) { @@ -742,39 +743,40 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { if (transQueueSize(&conn->reqsSentOut) == 0) { return; } + code = cliConnRemoveTimeoutMsg(conn); + // QUEUE_INIT(&set); + // SListFilterArg arg = {.id = 0, .pInst = pInst}; + // transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmTimoutReq, &arg, &set, -1); - QUEUE_INIT(&set); - SListFilterArg arg = {.id = 0, .pInst = pInst}; - transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmTimoutReq, &arg, &set, -1); + // while (!QUEUE_IS_EMPTY(&set)) { + // queue* el = QUEUE_HEAD(&set); + // QUEUE_REMOVE(el); + // SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); + // STraceId* trace = &pReq->msg.info.traceId; + // tDebug("%s conn %p req %s timeout, start to free", CONN_GET_INST_LABEL(conn), conn, + // TMSG_INFO(pReq->msg.msgType)); - while (!QUEUE_IS_EMPTY(&set)) { - queue* el = QUEUE_HEAD(&set); - QUEUE_REMOVE(el); - SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); - STraceId* trace = &pReq->msg.info.traceId; - tDebug("%s conn %p req %s timeout, start to free", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pReq->msg.msgType)); + // SReqCtx* pCtx = pReq ? pReq->ctx : NULL; + // STransMsg resp = {0}; + // resp.code = TSDB_CODE_RPC_TIMEOUT; + // resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; + // resp.info.cliVer = pInst->compatibilityVer; + // resp.info.ahandle = pCtx ? pCtx->ahandle : 0; + // resp.info.handle = pReq->msg.info.handle; + // if (pReq) { + // resp.info.traceId = pReq->msg.info.traceId; + // } - SReqCtx* pCtx = pReq ? pReq->ctx : NULL; - STransMsg resp = {0}; - resp.code = TSDB_CODE_RPC_TIMEOUT; - resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; - resp.info.cliVer = pInst->compatibilityVer; - resp.info.ahandle = pCtx ? pCtx->ahandle : 0; - resp.info.handle = pReq->msg.info.handle; - if (pReq) { - resp.info.traceId = pReq->msg.info.traceId; - } - - pReq->seq = 0; - code = cliNotifyCb(conn, pReq, &resp); - if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { - continue; - } else { - // already notify user - destroyReq(pReq); - // destroyReqWrapper(pReq, pThrd); - } - } + // pReq->seq = 0; + // code = cliNotifyCb(conn, pReq, &resp); + // if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { + // continue; + // } else { + // // already notify user + // destroyReq(pReq); + // // destroyReqWrapper(pReq, pThrd); + // } + // } return; } @@ -3711,6 +3713,7 @@ static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { } if (pConn->list && pConn->list->totaSize >= pInst->connLimitNum / 4) { tWarn("%s conn %p try to remove timeout msg since too many conn created", transLabel(pInst), pConn); + if (cliConnRemoveTimeoutMsg(pConn)) { tWarn("%s conn %p succ to remove timeout msg", transLabel(pInst), pConn); } From 2b466765a144a3d80d91fe3845fa709f8226c214 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 14 Oct 2024 19:20:38 +0800 Subject: [PATCH 222/240] reset timeout --- source/libs/transport/src/transCli.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 6797716c7b..5fcbdefe82 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -744,6 +744,9 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { return; } code = cliConnRemoveTimeoutMsg(conn); + if (code != 0) { + tDebug("%s conn %p do remove timeout msg since %s", CONN_GET_INST_LABEL(conn), conn); + } // QUEUE_INIT(&set); // SListFilterArg arg = {.id = 0, .pInst = pInst}; // transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmTimoutReq, &arg, &set, -1); From 19f0ed7506678ebca00156acdea92593fa327953 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 14 Oct 2024 19:21:24 +0800 Subject: [PATCH 223/240] reset timeout --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 5fcbdefe82..08dc0a74bc 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -745,7 +745,7 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { } code = cliConnRemoveTimeoutMsg(conn); if (code != 0) { - tDebug("%s conn %p do remove timeout msg since %s", CONN_GET_INST_LABEL(conn), conn); + tDebug("%s conn %p do remove timeout msg", CONN_GET_INST_LABEL(conn), conn); } // QUEUE_INIT(&set); // SListFilterArg arg = {.id = 0, .pInst = pInst}; From d43f7bd47af658cc147099f983202646c670096b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 14 Oct 2024 19:35:24 +0800 Subject: [PATCH 224/240] reset timeout --- source/libs/transport/src/transCli.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 08dc0a74bc..800d6e6c30 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -681,7 +681,7 @@ void cliHandleResp(SCliConn* conn) { if (cliMayRecycleConn(conn)) { return; } - cliConnCheckTimoutMsg(conn); + // cliConnCheckTimoutMsg(conn); cliConnMayUpdateTimer(conn, pInst->readTimeout * 1000); } @@ -1309,7 +1309,7 @@ static void cliBatchSendCb(uv_write_t* req, int status) { return; } - cliConnMayUpdateTimer(conn, pInst->readTimeout); + cliConnMayUpdateTimer(conn, pInst->readTimeout * 1000); if (conn->readerStart == 0) { code = uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); if (code != 0) { From de51fa24b3c9d7164f3998e4d9bfa3b425074395 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 14 Oct 2024 19:48:55 +0800 Subject: [PATCH 225/240] reset timeout --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 800d6e6c30..f409e1b0c7 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -480,9 +480,9 @@ int32_t cliGetReqBySeq(SCliConn* conn, int64_t seq, int32_t msgType, SCliReq** p int8_t cliMayRecycleConn(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; - if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && taosHashGetSize(conn->pQTable) == 0) { + cliResetConnTimer(conn); code = delConnFromHeapCache(pThrd->connHeapCache, conn); if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { tDebug("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, From 3aad2757efd7f2b056826b59fe0b12387499d730 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 14 Oct 2024 22:12:48 +0800 Subject: [PATCH 226/240] reset timeout --- source/libs/transport/src/trans.c | 2 +- source/libs/transport/src/transCli.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index a479920360..de129773a0 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -85,7 +85,7 @@ void* rpcOpen(const SRpcInit* pInit) { } pRpc->readTimeout = pInit->readTimeout; - if (pRpc->readTimeout <= 0) { + if (pRpc->readTimeout < 0) { pRpc->readTimeout = INT64_MAX; } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index f409e1b0c7..38f60bf412 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -704,7 +704,7 @@ bool filterToRmTimoutReq(void* key, void* arg) { SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000000); - if (filterArg && (elapse > filterArg->pInst->readTimeout)) { + if (filterArg && (elapse >= filterArg->pInst->readTimeout)) { return false; } else { return false; @@ -718,7 +718,7 @@ bool filterToDebug_timeoutMsg(void* key, void* arg) { SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { int64_t elapse = ((taosGetTimestampUs() - pReq->st) / 1000000); - if (filterArg && elapse > filterArg->pInst->readTimeout) { + if (filterArg && elapse >= filterArg->pInst->readTimeout) { tWarn("req %s timeout, elapse:%" PRId64 "ms", TMSG_INFO(pReq->msg.msgType), elapse); return false; } @@ -3612,7 +3612,7 @@ bool filterTimeoutReq(void* key, void* arg) { SCliReq* pReq = QUEUE_DATA(key, SCliReq, q); if (pReq->msg.info.qId == 0 && !REQUEST_NO_RESP(&pReq->msg) && pReq->ctx) { int64_t elapse = ((st - pReq->st) / 1000000); - if (listArg && elapse > listArg->pInst->readTimeout) { + if (listArg && elapse >= listArg->pInst->readTimeout) { return true; } else { return false; @@ -3632,7 +3632,7 @@ static void cliConnRemoveTimoutQidMsg(SCliConn* pConn, int64_t* st, queue* set) STransCtx* pCtx = (STransCtx*)pIter; int64_t* qid = taosHashGetKey(pIter, NULL); - if (((*st - pCtx->st) / 1000000) > pInst->readTimeout) { + if (((*st - pCtx->st) / 1000000) >= pInst->readTimeout) { code = taosHashRemove(pThrd->pIdConnTable, qid, sizeof(*qid)); if (code != 0) { tError("%s conn %p failed to remove state sid:%" PRId64 " since %s", CONN_GET_INST_LABEL(pConn), pConn, *qid, @@ -3674,6 +3674,7 @@ static void cliConnRemoveTimeoutNoQidMsg(SCliConn* pConn, int64_t* st, queue* se SCliThrd* pThrd = pConn->hostThrd; STrans* pInst = pThrd->pInst; SListFilterArg arg = {.id = *st, .pInst = pInst}; + transQueueRemoveByFilter(&pConn->reqsSentOut, filterTimeoutReq, &arg, set, -1); transQueueRemoveByFilter(&pConn->reqsToSend, filterTimeoutReq, &arg, set, -1); return; } From dfbcf09ecdaa1c6d02b95ff14bc701d1a2145e22 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 15 Oct 2024 08:46:36 +0800 Subject: [PATCH 227/240] reset timeout --- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 8d58978980..0a23e9a022 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -16,8 +16,8 @@ #define _DEFAULT_SOURCE #include "dmMgmt.h" #include "qworker.h" -#include "tversion.h" #include "tanal.h" +#include "tversion.h" static inline void dmSendRsp(SRpcMsg *pMsg) { if (rpcSendResponse(pMsg) != 0) { @@ -471,7 +471,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) { rpcInit.supportBatch = 1; rpcInit.shareConnLimit = tsShareConnLimit * 2; rpcInit.timeToGetConn = tsTimeToGetAvailableConn; - rpcInit.startReadTimer = 1; + rpcInit.startReadTimer = 0; rpcInit.readTimeout = 0; if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) { From 40e4d9db03d8cde00b97f082fd51229e5ac41a0f Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 15 Oct 2024 10:39:14 +0800 Subject: [PATCH 228/240] reset timeout --- source/libs/transport/src/transCli.c | 46 +++++----------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 38f60bf412..fc0122e1a0 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -734,7 +734,7 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; - transQueueRemoveByFilter(&conn->reqsSentOut, filterToDebug_timeoutMsg, NULL, &set, -1); + // transQueueRemoveByFilter(&conn->reqsSentOut, filterToDebug_timeoutMsg, NULL, &set, -1); if (pInst->startReadTimer == 0) { return; @@ -746,42 +746,12 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { code = cliConnRemoveTimeoutMsg(conn); if (code != 0) { tDebug("%s conn %p do remove timeout msg", CONN_GET_INST_LABEL(conn), conn); + if (!cliMayRecycleConn(conn)) { + TAOS_UNUSED(transHeapBalance(conn->heap, conn)); + } + } else { + TAOS_UNUSED(cliMayRecycleConn(conn)); } - // QUEUE_INIT(&set); - // SListFilterArg arg = {.id = 0, .pInst = pInst}; - // transQueueRemoveByFilter(&conn->reqsSentOut, filterToRmTimoutReq, &arg, &set, -1); - - // while (!QUEUE_IS_EMPTY(&set)) { - // queue* el = QUEUE_HEAD(&set); - // QUEUE_REMOVE(el); - // SCliReq* pReq = QUEUE_DATA(el, SCliReq, q); - // STraceId* trace = &pReq->msg.info.traceId; - // tDebug("%s conn %p req %s timeout, start to free", CONN_GET_INST_LABEL(conn), conn, - // TMSG_INFO(pReq->msg.msgType)); - - // SReqCtx* pCtx = pReq ? pReq->ctx : NULL; - // STransMsg resp = {0}; - // resp.code = TSDB_CODE_RPC_TIMEOUT; - // resp.msgType = pReq ? pReq->msg.msgType + 1 : 0; - // resp.info.cliVer = pInst->compatibilityVer; - // resp.info.ahandle = pCtx ? pCtx->ahandle : 0; - // resp.info.handle = pReq->msg.info.handle; - // if (pReq) { - // resp.info.traceId = pReq->msg.info.traceId; - // } - - // pReq->seq = 0; - // code = cliNotifyCb(conn, pReq, &resp); - // if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { - // continue; - // } else { - // // already notify user - // destroyReq(pReq); - // // destroyReqWrapper(pReq, pThrd); - // } - // } - - return; } void cliConnTimeout__checkReq(uv_timer_t* handle) { SCliConn* conn = handle->data; @@ -921,7 +891,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { arg->param2 = thrd; STrans* pInst = thrd->pInst; - conn->task = transDQSched(thrd->timeoutQueue, doCloseIdleConn, arg, 10 * CONN_PERSIST_TIME(pInst->idleTime)); + conn->task = transDQSched(thrd->timeoutQueue, doCloseIdleConn, arg, (10 * CONN_PERSIST_TIME(pInst->idleTime) / 3)); } } @@ -3923,7 +3893,7 @@ int32_t transHeapUpdateFailTs(SHeap* heap, SCliConn* p) { } int32_t transHeapBalance(SHeap* heap, SCliConn* p) { - if (p->inHeap == 0 && heap == NULL || heap->heap == NULL) { + if (p->inHeap == 0 || heap == NULL || heap->heap == NULL) { return 0; } heapRemove(heap->heap, &p->node); From 6fdf9f8a9f6c58325b096f8dc39eafd99d87d6ae Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 15 Oct 2024 17:26:18 +0800 Subject: [PATCH 229/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4e710fbaeb..82dc099940 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3119,9 +3119,9 @@ int32_t transSendRequest(void* pInstRef, const SEpSet* pEpSet, STransMsg* pReq, return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - if (pReq->msgType == TDMT_SCH_DROP_TASK) { - TAOS_UNUSED(transReleaseCliHandle(pReq->info.handle)); - } + // if (pReq->msgType == TDMT_SCH_DROP_TASK) { + // TAOS_UNUSED(transReleaseCliHandle(pReq->info.handle)); + // } transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; @@ -3172,9 +3172,9 @@ int32_t transSendRequestWithId(void* pInstRef, const SEpSet* pEpSet, STransMsg* return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - if (pReq->msgType == TDMT_SCH_DROP_TASK) { - TAOS_UNUSED(transReleaseCliHandle(pReq->info.handle)); - } + // if (pReq->msgType == TDMT_SCH_DROP_TASK) { + // TAOS_UNUSED(transReleaseCliHandle(pReq->info.handle)); + // } transReleaseExHandle(transGetRefMgt(), *transpointId); transReleaseExHandle(transGetInstMgt(), (int64_t)pInstRef); return 0; From d6f1ab52fa8b7ba015ff26993e8da4e8fc5babe1 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Oct 2024 10:35:17 +0800 Subject: [PATCH 230/240] refactor transport --- source/libs/transport/src/transCli.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 82dc099940..28e9d5602a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -480,6 +480,7 @@ int32_t cliGetReqBySeq(SCliConn* conn, int64_t seq, int32_t msgType, SCliReq** p int8_t cliMayRecycleConn(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; + STrans* pInst = pThrd->pInst; if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && taosHashGetSize(conn->pQTable) == 0) { cliResetConnTimer(conn); @@ -496,6 +497,10 @@ int8_t cliMayRecycleConn(SCliConn* conn) { } addConnToPool(pThrd->pool, conn); return 1; + } else if ((transQueueSize(&conn->reqsToSend) == 0) && + ((pInst->shareConnLimit >= 2) && (transQueueSize(&conn->reqsSentOut) > 0) && + transQueueSize(&conn->reqsSentOut) <= pInst->shareConnLimit / 2)) { + TAOS_UNUSED(transHeapBalance(conn->heap, conn)); } return 0; } From bd132a8fbd1e85264417e044ba655771a4335349 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Oct 2024 11:17:54 +0800 Subject: [PATCH 231/240] refactor transport --- source/libs/transport/src/transCli.c | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 28e9d5602a..25dcae301a 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -497,10 +497,34 @@ int8_t cliMayRecycleConn(SCliConn* conn) { } addConnToPool(pThrd->pool, conn); return 1; - } else if ((transQueueSize(&conn->reqsToSend) == 0) && - ((pInst->shareConnLimit >= 2) && (transQueueSize(&conn->reqsSentOut) > 0) && - transQueueSize(&conn->reqsSentOut) <= pInst->shareConnLimit / 2)) { + } else if ((transQueueSize(&conn->reqsToSend) == 0) && (transQueueSize(&conn->reqsSentOut) == 0) && + (taosHashGetSize(conn->pQTable) != 0)) { + tDebug("%s conn %p do balance directly", CONN_GET_INST_LABEL(conn), conn, conn); TAOS_UNUSED(transHeapBalance(conn->heap, conn)); + } else if ((transQueueSize(&conn->reqsToSend) == 0) && + ((pInst->shareConnLimit >= 4) && ((transQueueSize(&conn->reqsSentOut) > 0) && + transQueueSize(&conn->reqsSentOut) < pInst->shareConnLimit / 2))) { + SCliConn* topConn = NULL; + if (conn->heap != NULL) { + code = transHeapGet(conn->heap, &topConn); + if (code != 0) { + tDebug("%s conn %p failed to get top conn since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + return 0; + } + + if (topConn == conn) { + return 0; + } + int32_t topReqs = transQueueSize(&topConn->reqsSentOut) + transQueueSize(&topConn->reqsToSend); + int32_t currReqs = transQueueSize(&conn->reqsSentOut) + transQueueSize(&conn->reqsToSend); + if (topReqs <= currReqs) { + return 0; + } else { + tDebug("%s conn %p do balance conn heap since top conn has more reqs, topConnReqs:%d, currConnReqs:%d", + CONN_GET_INST_LABEL(conn), conn, topReqs, currReqs); + TAOS_UNUSED(transHeapBalance(conn->heap, conn)); + } + } } return 0; } From 5e39dd9b3644241b27e118c0c05a569733c2d61b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Oct 2024 11:26:06 +0800 Subject: [PATCH 232/240] refactor transport --- source/libs/transport/src/transCli.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 25dcae301a..47bd2ee196 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -481,6 +481,11 @@ int8_t cliMayRecycleConn(SCliConn* conn) { int32_t code = 0; SCliThrd* pThrd = conn->hostThrd; STrans* pInst = pThrd->pInst; + + tTrace("%s conn %p in-process req summary:reqsToSend:%d, reqsSentOut:%d, statusTableSize:%d", + CONN_GET_INST_LABEL(conn), conn, transQueueSize(&conn->reqsToSend), transQueueSize(&conn->reqsSentOut), + taosHashGetSize(conn->pQTable)); + if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && taosHashGetSize(conn->pQTable) == 0) { cliResetConnTimer(conn); @@ -518,6 +523,8 @@ int8_t cliMayRecycleConn(SCliConn* conn) { int32_t topReqs = transQueueSize(&topConn->reqsSentOut) + transQueueSize(&topConn->reqsToSend); int32_t currReqs = transQueueSize(&conn->reqsSentOut) + transQueueSize(&conn->reqsToSend); if (topReqs <= currReqs) { + tTrace("%s conn %p not balance conn heap since top conn has less req, topConnReqs:%d, currConnReqs:%d", + CONN_GET_INST_LABEL(conn), conn, topReqs, currReqs); return 0; } else { tDebug("%s conn %p do balance conn heap since top conn has more reqs, topConnReqs:%d, currConnReqs:%d", From 0afec9a5f44e183f9f945be271804aa0ac0e0165 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Oct 2024 11:39:36 +0800 Subject: [PATCH 233/240] refactor transport --- source/libs/transport/src/transCli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 47bd2ee196..1d408e276d 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -504,7 +504,7 @@ int8_t cliMayRecycleConn(SCliConn* conn) { return 1; } else if ((transQueueSize(&conn->reqsToSend) == 0) && (transQueueSize(&conn->reqsSentOut) == 0) && (taosHashGetSize(conn->pQTable) != 0)) { - tDebug("%s conn %p do balance directly", CONN_GET_INST_LABEL(conn), conn, conn); + tDebug("%s conn %p do balance directly", CONN_GET_INST_LABEL(conn), conn); TAOS_UNUSED(transHeapBalance(conn->heap, conn)); } else if ((transQueueSize(&conn->reqsToSend) == 0) && ((pInst->shareConnLimit >= 4) && ((transQueueSize(&conn->reqsSentOut) > 0) && From 29b07a350ce1da85d13b073b87849a9375f32acb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Oct 2024 11:41:59 +0800 Subject: [PATCH 234/240] refactor transport --- source/libs/transport/src/transCli.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 1d408e276d..3047843270 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -506,9 +506,7 @@ int8_t cliMayRecycleConn(SCliConn* conn) { (taosHashGetSize(conn->pQTable) != 0)) { tDebug("%s conn %p do balance directly", CONN_GET_INST_LABEL(conn), conn); TAOS_UNUSED(transHeapBalance(conn->heap, conn)); - } else if ((transQueueSize(&conn->reqsToSend) == 0) && - ((pInst->shareConnLimit >= 4) && ((transQueueSize(&conn->reqsSentOut) > 0) && - transQueueSize(&conn->reqsSentOut) < pInst->shareConnLimit / 2))) { + } else { SCliConn* topConn = NULL; if (conn->heap != NULL) { code = transHeapGet(conn->heap, &topConn); From 0cb78021e22fd4f3942ba72f970567d5cefb3089 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 16 Oct 2024 19:46:12 +0800 Subject: [PATCH 235/240] refactor transport --- source/libs/transport/inc/transComm.h | 38 +++++++++------------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 42ee0894d0..3a4f11ac81 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -278,31 +278,19 @@ bool transAsyncPoolIsEmpty(SAsyncPool* pool); } \ } while (0) -#define ASYNC_CHECK_HANDLE(idMgt, id, exh1) \ - do { \ - if (id > 0) { \ - SExHandle* exh2 = transAcquireExHandle(idMgt, id); \ - 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) { \ - tTrace("handle step2"); \ - SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), id); \ - 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; \ - } \ - } else if (id < 0) { \ - tTrace("handle step3"); \ - goto _return2; \ - } \ +#define ASYNC_CHECK_HANDLE(idMgt, id, exh1) \ + do { \ + if (id > 0) { \ + SExHandle* exh2 = transAcquireExHandle(idMgt, id); \ + if (exh2 == NULL || exh1 != exh2 || (exh2 != NULL && exh2->refId != id)) { \ + tError("handle not match, exh1:%p, exh2:%p, refId:%"PRId64"", exh1, exh2, id); \ + code = TSDB_CODE_INVALID_MSG; \ + goto _return1; \ + } \ + } else { \ + tError("invalid handle to release"); \ + goto _return2; \ + } \ } while (0) int32_t transInitBuffer(SConnBuffer* buf); From 36b3a9c398cc9b5c5badfd635fc204e02ad0fd85 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 21 Oct 2024 16:32:08 +0800 Subject: [PATCH 236/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- include/os/osSocket.h | 1 - include/util/taoserror.h | 8 +- log | 205 ------------------------- qid | 216 --------------------------- source/client/src/clientImpl.c | 28 ++-- source/libs/transport/src/transSvr.c | 11 ++ source/util/src/terror.c | 12 +- source/util/src/theap.c | 10 +- sql0 | 140 ----------------- sql1 | 141 ----------------- 10 files changed, 40 insertions(+), 732 deletions(-) delete mode 100644 log delete mode 100644 qid delete mode 100644 sql0 delete mode 100644 sql1 diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 9e51799512..49acf285ee 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -170,7 +170,6 @@ const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len); uint64_t taosHton64(uint64_t val); uint64_t taosNtoh64(uint64_t val); -int32_t taosSetSockOpt2(int32_t fd); #ifdef __cplusplus } #endif diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 75588f6978..a4bb59bf60 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -93,10 +93,10 @@ int32_t taosGetErrSize(); #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) -#define TSDB_CODE_RPC_ASYNC_IN_PROCESS TAOS_DEF_ERROR_CODE(0, 0x0028) -#define TSDB_CODE_RPC_NO_STATE TAOS_DEF_ERROR_CODE(0, 0x0029) -#define TSDB_CODE_RPC_STATE_DROPED TAOS_DEF_ERROR_CODE(0, 0x002A) +#define TSDB_CODE_RPC_ASYNC_MODULE_QUIT TAOS_DEF_ERROR_CODE(0, 0x0027) +#define TSDB_CODE_RPC_ASYNC_IN_PROCESS TAOS_DEF_ERROR_CODE(0, 0x0028) +#define TSDB_CODE_RPC_NO_STATE TAOS_DEF_ERROR_CODE(0, 0x0029) +#define TSDB_CODE_RPC_STATE_DROPED TAOS_DEF_ERROR_CODE(0, 0x002A) //common & util #define TSDB_CODE_OPS_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x0100) // diff --git a/log b/log deleted file mode 100644 index de7cd0bfa7..0000000000 --- a/log +++ /dev/null @@ -1,205 +0,0 @@ -10060:09/09 19:07:23.425713 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -10062:09/09 19:07:23.425770 00161875 C RPC DND-S conn 0x7f73780418e0 heartbeat received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:184, cost:161us, seqNum:9, qid:15, gtid:0xadc8d77787a1000d:0x70b71d6778700015 -10063:09/09 19:07:23.425776 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77787a1000d:0x70b71d6778700015 -10098:09/09 19:07:23.426118 00161914 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d77787a1000d:0x70b71d6778700015 -10105:09/09 19:07:23.426263 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -10106:09/09 19:07:23.426291 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -10107:09/09 19:07:23.426299 00161875 C RPC DND-S conn 0x7f73780418e0 heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:855, seqNum:9, qid:15, gtid:0xadc8d77787a1000d:0x70b71d6778700015 -10108:09/09 19:07:23.426303 00161875 C RPC conn 0x7f73780418e0 ref count:2 -10109:09/09 19:07:23.426358 00161875 C RPC DND-S conn 0x7f73780418e0 send data -10110:09/09 19:07:23.426383 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:9, qid:15, gtid:0xadc8d77787a1000d:0x70b71d6778700015 -10112:09/09 19:07:23.426393 00161875 C RPC conn 0x7f73780418e0 ref count:1 -10285:09/09 19:07:24.604388 00161881 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0x0:0x70b71d6775200005 -10291:09/09 19:07:24.604484 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -10292:09/09 19:07:24.604492 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -10293:09/09 19:07:24.604497 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:116, seqNum:1, qid:4, gtid:0x0:0x70b71d6775200005 -10294:09/09 19:07:24.604502 00161875 C RPC conn 0x7f73780418e0 ref count:2 -10295:09/09 19:07:24.604552 00161875 C RPC DND-S conn 0x7f73780418e0 send data -10296:09/09 19:07:24.604575 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:1, qid:4, gtid:0x0:0x70b71d6775200005 -10298:09/09 19:07:24.604585 00161875 C RPC conn 0x7f73780418e0 ref count:1 -10463:09/09 19:07:24.866345 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -10465:09/09 19:07:24.866385 00161875 C RPC DND-S conn 0x7f73780418e0 vnode-batch-meta received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:90, cost:107us, seqNum:10, qid:0, gtid:0xadc8d7778d40000e:0x70b71d6778d00017 -10466:09/09 19:07:24.866389 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d00017 -10542:09/09 19:07:24.867015 00162315 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d7778d40000e:0x70b71d6778d00017 -10549:09/09 19:07:24.867083 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -10550:09/09 19:07:24.867088 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -10551:09/09 19:07:24.867093 00161875 C RPC DND-S conn 0x7f73780418e0 vnode-batch-meta is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:329, seqNum:10, qid:0, gtid:0xadc8d7778d40000e:0x70b71d6778d00017 -10552:09/09 19:07:24.867097 00161875 C RPC conn 0x7f73780418e0 ref count:2 -10553:09/09 19:07:24.867137 00161875 C RPC DND-S conn 0x7f73780418e0 send data -10554:09/09 19:07:24.867144 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:10, qid:0, gtid:0xadc8d7778d40000e:0x70b71d6778d00017 -10556:09/09 19:07:24.867153 00161875 C RPC conn 0x7f73780418e0 ref count:1 -10601:09/09 19:07:24.869034 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -10603:09/09 19:07:24.869064 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:41, cost:93us, seqNum:11, qid:16, gtid:0x0:0x70b71d6778d00019 -10604:09/09 19:07:24.869067 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0x0:0x70b71d6778d00019 -10626:09/09 19:07:24.869574 00162315 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback -10635:09/09 19:07:24.869602 00162315 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0x0:0x70b71d6778d00019 -10643:09/09 19:07:24.869659 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback -10644:09/09 19:07:24.869661 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:16 -10645:09/09 19:07:24.869664 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ -10648:09/09 19:07:24.869670 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -10649:09/09 19:07:24.869672 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -10650:09/09 19:07:24.869674 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:116, seqNum:11, qid:16, gtid:0x0:0x70b71d6778d00019 -10651:09/09 19:07:24.869676 00161875 C RPC conn 0x7f73780418e0 ref count:2 -10652:09/09 19:07:24.869698 00161875 C RPC DND-S conn 0x7f73780418e0 send data -10653:09/09 19:07:24.869701 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:11, qid:16, gtid:0x0:0x70b71d6778d00019 -10655:09/09 19:07:24.869705 00161875 C RPC conn 0x7f73780418e0 ref count:1 -10656:09/09 19:07:24.869711 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -10658:09/09 19:07:24.869727 00161875 C RPC DND-S conn 0x7f73780418e0 query received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:1312, cost:373us, seqNum:12, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b -10659:09/09 19:07:24.869729 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b -10668:09/09 19:07:24.869752 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback -10677:09/09 19:07:24.869921 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback -10678:09/09 19:07:24.869925 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:18 -10679:09/09 19:07:24.869929 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ -10858:09/09 19:07:24.872444 00162312 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d7778d40000e:0x70b71d6778d0001b -10867:09/09 19:07:24.872486 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -10869:09/09 19:07:24.872493 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -10870:09/09 19:07:24.872496 00161875 C RPC DND-S conn 0x7f73780418e0 query-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:130, seqNum:12, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b -10871:09/09 19:07:24.872498 00161875 C RPC conn 0x7f73780418e0 ref count:2 -10872:09/09 19:07:24.872518 00161875 C RPC DND-S conn 0x7f73780418e0 send data -10873:09/09 19:07:24.872521 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:12, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b -10875:09/09 19:07:24.872525 00161875 C RPC conn 0x7f73780418e0 ref count:1 -10952:09/09 19:07:24.873453 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -10954:09/09 19:07:24.873476 00161875 C RPC DND-S conn 0x7f73780418e0 merge-query received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:595, cost:107us, seqNum:13, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d -10955:09/09 19:07:24.873479 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d -10964:09/09 19:07:24.873500 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback -10972:09/09 19:07:24.873553 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback -10977:09/09 19:07:24.873556 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:20 -10981:09/09 19:07:24.873672 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ -11153:09/09 19:07:24.874866 00163053 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d7778d40000e:0x70b71d6778d0001d -11159:09/09 19:07:24.874914 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -11160:09/09 19:07:24.874926 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -11162:09/09 19:07:24.874930 00161875 C RPC DND-S conn 0x7f73780418e0 merge-query-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:111, seqNum:13, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d -11166:09/09 19:07:24.874933 00161875 C RPC conn 0x7f73780418e0 ref count:2 -11167:09/09 19:07:24.875549 00161875 C RPC DND-S conn 0x7f73780418e0 send data -11168:09/09 19:07:24.875602 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:13, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d -11170:09/09 19:07:24.875646 00161875 C RPC conn 0x7f73780418e0 ref count:1 -11171:09/09 19:07:24.876014 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -11173:09/09 19:07:24.876039 00161875 C RPC DND-S conn 0x7f73780418e0 merge-fetch received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:44, cost:62us, seqNum:14, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001e -11174:09/09 19:07:24.876042 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d0001e -11200:09/09 19:07:24.876181 00162337 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d7778d40000e:0x70b71d6778d0001e -11209:09/09 19:07:24.876215 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -11210:09/09 19:07:24.876217 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -11211:09/09 19:07:24.876219 00161875 C RPC DND-S conn 0x7f73780418e0 merge-fetch-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:1110, seqNum:14, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001e -11212:09/09 19:07:24.876221 00161875 C RPC conn 0x7f73780418e0 ref count:2 -11213:09/09 19:07:24.876246 00161875 C RPC DND-S conn 0x7f73780418e0 send data -11214:09/09 19:07:24.876249 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:14, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001e -11216:09/09 19:07:24.876253 00161875 C RPC conn 0x7f73780418e0 ref count:1 -11217:09/09 19:07:24.876706 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -11219:09/09 19:07:24.876732 00161875 C RPC DND-S conn 0x7f73780418e0 drop-task received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:48, cost:54us, seqNum:15, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001f -11220:09/09 19:07:24.876734 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d0001f -11235:09/09 19:07:24.876834 00162315 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:18 -11255:09/09 19:07:24.877107 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -11257:09/09 19:07:24.877134 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -11259:09/09 19:07:24.877149 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b -11260:09/09 19:07:24.877169 00161875 C RPC conn 0x7f73780418e0 ref count:2 -11263:09/09 19:07:24.877193 00161875 C RPC DND-S conn 0x7f73780418e0 send data -11264:09/09 19:07:24.877294 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:18, gtid:0xadc8d7778d40000e:0x70b71d6778d0001b -11266:09/09 19:07:24.877323 00161875 C RPC conn 0x7f73780418e0 ref count:1 -11270:09/09 19:07:24.877340 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -11275:09/09 19:07:24.877458 00161875 C RPC DND-S conn 0x7f73780418e0 drop-task received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:48, cost:717us, seqNum:16, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d00021 -11276:09/09 19:07:24.877461 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d7778d40000e:0x70b71d6778d00021 -11342:09/09 19:07:24.877977 00162337 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:20 -11359:09/09 19:07:24.878137 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -11361:09/09 19:07:24.878182 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -11363:09/09 19:07:24.878186 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d -11364:09/09 19:07:24.878189 00161875 C RPC conn 0x7f73780418e0 ref count:2 -11365:09/09 19:07:24.878208 00161875 C RPC DND-S conn 0x7f73780418e0 send data -11366:09/09 19:07:24.878220 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:20, gtid:0xadc8d7778d40000e:0x70b71d6778d0001d -11368:09/09 19:07:24.878224 00161875 C RPC conn 0x7f73780418e0 ref count:1 -11944:09/09 19:07:26.247094 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -11947:09/09 19:07:26.247153 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:41, cost:126us, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 -11949:09/09 19:07:26.247163 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0x0:0x70b71d6779200023 -11981:09/09 19:07:26.247510 00162315 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback -11992:09/09 19:07:26.247599 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback -11993:09/09 19:07:26.247602 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:22 -11994:09/09 19:07:26.247605 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ -11995:09/09 19:07:26.247578 00162315 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:16 -12007:09/09 19:07:26.247821 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -12011:09/09 19:07:26.247956 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -12013:09/09 19:07:26.247973 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:16, gtid:0x0:0x70b71d6778d00019 -12020:09/09 19:07:26.248038 00162315 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0x0:0x70b71d6779200023 -12026:09/09 19:07:26.247975 00161875 C RPC conn 0x7f73780418e0 ref count:2 -12031:09/09 19:07:26.248166 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -12033:09/09 19:07:26.248206 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -12034:09/09 19:07:26.248217 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:116, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 -12037:09/09 19:07:26.248248 00161875 C RPC conn 0x7f73780418e0 ref count:3 -12043:09/09 19:07:26.248296 00161875 C RPC DND-S conn 0x7f73780418e0 send data -12044:09/09 19:07:26.248341 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:16, gtid:0x0:0x70b71d6778d00019 -12049:09/09 19:07:26.248433 00161875 C RPC conn 0x7f73780418e0 ref count:2 -12050:09/09 19:07:26.248441 00161875 C RPC DND-S conn 0x7f73780418e0 send data -12054:09/09 19:07:26.248503 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 -12074:09/09 19:07:26.248787 00161875 C RPC conn 0x7f73780418e0 ref count:1 -12076:09/09 19:07:26.248887 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -12082:09/09 19:07:26.248920 00161875 C RPC DND-S conn 0x7f73780418e0 query received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:1312, cost:1830us, seqNum:18, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 -12090:09/09 19:07:26.249021 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d6779200025 -12109:09/09 19:07:26.249567 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback -12127:09/09 19:07:26.249617 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback -12130:09/09 19:07:26.249623 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:24 -12139:09/09 19:07:26.249633 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ -12302:09/09 19:07:26.251246 00162269 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d77792a60010:0x70b71d6779200025 -12317:09/09 19:07:26.251495 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -12318:09/09 19:07:26.251597 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -12319:09/09 19:07:26.251602 00161875 C RPC DND-S conn 0x7f73780418e0 query-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:130, seqNum:18, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 -12320:09/09 19:07:26.251604 00161875 C RPC conn 0x7f73780418e0 ref count:2 -12321:09/09 19:07:26.251611 00161875 C RPC DND-S conn 0x7f73780418e0 send data -12322:09/09 19:07:26.251613 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:18, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 -12324:09/09 19:07:26.251616 00161875 C RPC conn 0x7f73780418e0 ref count:1 -12327:09/09 19:07:26.290976 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -12329:09/09 19:07:26.291023 00161875 C RPC DND-S conn 0x7f73780418e0 merge-query received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:595, cost:96us, seqNum:19, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 -12330:09/09 19:07:26.291026 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d6779200027 -12339:09/09 19:07:26.291064 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback -12347:09/09 19:07:26.291142 00161875 C RPC DND-S conn 0x7f73780418e0 register brokenlink callback -12348:09/09 19:07:26.291145 00161875 C RPC DND-S conn 0x7f73780418e0 start to register brokenlink callback, qid:26 -12351:09/09 19:07:26.291148 00161875 C RPC conn 0x7f73780418e0 register brokenlink callback succ -12528:09/09 19:07:26.292905 00162273 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d77792a60010:0x70b71d6779200027 -12532:09/09 19:07:26.292977 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -12536:09/09 19:07:26.292980 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -12538:09/09 19:07:26.293019 00161875 C RPC DND-S conn 0x7f73780418e0 merge-query-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:111, seqNum:19, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 -12541:09/09 19:07:26.293025 00161875 C RPC conn 0x7f73780418e0 ref count:2 -12542:09/09 19:07:26.293054 00161875 C RPC DND-S conn 0x7f73780418e0 send data -12543:09/09 19:07:26.293068 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:19, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 -12545:09/09 19:07:26.293073 00161875 C RPC conn 0x7f73780418e0 ref count:1 -12546:09/09 19:07:26.293505 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -12548:09/09 19:07:26.293524 00161875 C RPC DND-S conn 0x7f73780418e0 merge-fetch received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:44, cost:65us, seqNum:20, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200028 -12549:09/09 19:07:26.293526 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d6779200028 -12575:09/09 19:07:26.293624 00162337 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0xadc8d77792a60010:0x70b71d6779200028 -12579:09/09 19:07:26.293691 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -12581:09/09 19:07:26.293694 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -12582:09/09 19:07:26.293711 00161875 C RPC DND-S conn 0x7f73780418e0 merge-fetch-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:1110, seqNum:20, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200028 -12583:09/09 19:07:26.293733 00161875 C RPC conn 0x7f73780418e0 ref count:2 -12588:09/09 19:07:26.293847 00161875 C RPC DND-S conn 0x7f73780418e0 send data -12589:09/09 19:07:26.293861 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:20, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200028 -12591:09/09 19:07:26.293866 00161875 C RPC conn 0x7f73780418e0 ref count:1 -12602:09/09 19:07:26.294162 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -12609:09/09 19:07:26.294319 00161875 C RPC DND-S conn 0x7f73780418e0 drop-task received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:48, cost:204us, seqNum:21, qid:26, gtid:0xadc8d77792a60010:0x70b71d677920002a -12610:09/09 19:07:26.294508 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d677920002a -12663:09/09 19:07:26.295131 00162337 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:26 -12680:09/09 19:07:26.295340 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -12682:09/09 19:07:26.295381 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -12684:09/09 19:07:26.295419 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 -12685:09/09 19:07:26.295431 00161875 C RPC conn 0x7f73780418e0 ref count:2 -12686:09/09 19:07:26.295510 00161875 C RPC DND-S conn 0x7f73780418e0 send data -12687:09/09 19:07:26.295527 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:26, gtid:0xadc8d77792a60010:0x70b71d6779200027 -12689:09/09 19:07:26.295532 00161875 C RPC conn 0x7f73780418e0 ref count:1 -12690:09/09 19:07:26.295540 00161875 C RPC DND-S conn 0x7f73780418e0 not reset read buf -12692:09/09 19:07:26.295557 00161875 C RPC DND-S conn 0x7f73780418e0 drop-task received from 127.0.0.1:59940, local info:127.0.0.1:6100, len:48, cost:1397us, seqNum:22, qid:24, gtid:0xadc8d77792a60010:0x70b71d677920002b -12693:09/09 19:07:26.295559 00161875 C RPC DND-S handle 0x7f737802b760 conn:0x7f73780418e0 translated to app, refId:8, gtid:0xadc8d77792a60010:0x70b71d677920002b -12708:09/09 19:07:26.295660 00162315 C RPC DND-S conn 0x7f73780418e0 start to send task-release, qid:24 -12713:09/09 19:07:26.295705 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -12716:09/09 19:07:26.295713 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -12718:09/09 19:07:26.295749 00161875 C RPC DND-S conn 0x7f73780418e0 task-release is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:91, seqNum:0, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 -12719:09/09 19:07:26.295752 00161875 C RPC conn 0x7f73780418e0 ref count:2 -12721:09/09 19:07:26.295774 00161875 C RPC DND-S conn 0x7f73780418e0 send data -12722:09/09 19:07:26.295795 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:0, qid:24, gtid:0xadc8d77792a60010:0x70b71d6779200025 -12724:09/09 19:07:26.295800 00161875 C RPC conn 0x7f73780418e0 ref count:1 -12939:09/09 19:07:27.279390 00161881 C RPC conn 0x7f73780418e0 start to send resp (1/2), gtid:0x0:0x70b71d6779200023 -12943:09/09 19:07:27.279480 00161875 C RPC DND-S conn 0x7f73780418e0 start to send resp (2/2) -12944:09/09 19:07:27.279486 00161875 C RPC DND-S conn 0x7f73780418e0 has 1 msg to send -12945:09/09 19:07:27.279491 00161875 C RPC DND-S conn 0x7f73780418e0 query-heartbeat-rsp is sent to 127.0.0.1:59940, local info:127.0.0.1:6100, len:116, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 -12946:09/09 19:07:27.279494 00161875 C RPC conn 0x7f73780418e0 ref count:2 -12947:09/09 19:07:27.279530 00161875 C RPC DND-S conn 0x7f73780418e0 send data -12948:09/09 19:07:27.279560 00161875 C RPC DND-S conn 0x7f73780418e0 msg already send out, seqNum:17, qid:22, gtid:0x0:0x70b71d6779200023 -12950:09/09 19:07:27.279585 00161875 C RPC conn 0x7f73780418e0 ref count:1 -13094:09/09 19:07:27.747059 00161875 C RPC DND-S conn 0x7f73780418e0 read error:EOF -13095:09/09 19:07:27.747080 00161875 C RPC conn 0x7f73780418e0 to be destroyed -13098:09/09 19:07:27.747108 00161875 C RPC DND-S conn 0x7f73780418e0 destroy diff --git a/qid b/qid deleted file mode 100644 index d8a8431ea0..0000000000 --- a/qid +++ /dev/null @@ -1,216 +0,0 @@ -11802:09/09 19:41:59.586660 00211996 C RPC DND-S conn 0x7fa218014af0 query received from 127.0.0.1:37174, local info:127.0.0.1:6100, len:1312, cost:589us, seqNum:16, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 -11803:09/09 19:41:59.586682 00211996 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 prerocessQuery start, handle:0x7fa218021f60, SQL:select * from test.sp; -11804:09/09 19:41:59.586684 00211994 C RPC DND-S conn 0x7fa210002100 query received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:1312, cost:642us, seqNum:15, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 -11806:09/09 19:41:59.586698 00211994 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 prerocessQuery start, handle:0x7fa210010ec0, SQL:select * from test.sp; -11807:09/09 19:41:59.586700 00211996 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status added, newStatus:INIT -11808:09/09 19:41:59.586713 00211996 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 prerocessQuery end, handle:0x7fa218021f60, code:0 -11810:09/09 19:41:59.586728 00211994 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status added, newStatus:INIT -11811:09/09 19:41:59.586734 00211994 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 prerocessQuery end, handle:0x7fa210010ec0, code:0 -11818:09/09 19:41:59.586785 00212137 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processQuery start, node:0x7fa24d7e8f50, type:query, compress:0, handle:0x7fa210010ec0, SQL:select * from test.sp; -11819:09/09 19:41:59.586795 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to handle event at phase PRE_QUERY -11820:09/09 19:41:59.586802 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status updated from INIT to EXECUTING -11821:09/09 19:41:59.586805 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 end to handle event at phase PRE_QUERY, code:success -11822:09/09 19:41:59.586816 00212138 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processQuery start, node:0x7fa24cfe7f50, type:query, compress:0, handle:0x7fa218021f60, SQL:select * from test.sp; -11823:09/09 19:41:59.586831 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to handle event at phase PRE_QUERY -11824:09/09 19:41:59.586837 00212137 C QRY start to create task, TID:0xa QID:0x2e20039735a00008, vgId:2 -11825:09/09 19:41:59.586840 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status updated from INIT to EXECUTING -11826:09/09 19:41:59.586845 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 end to handle event at phase PRE_QUERY, code:success -11827:09/09 19:41:59.586878 00212137 C QRY extract queried table list completed, 1 tables, elapsed time:0.00 ms TID:0xa QID:0x2e20039735a00008 -11828:09/09 19:41:59.586887 00212137 C QRY generate group id map completed, elapsed time:0.01 ms TID:0xa QID:0x2e20039735a00008 -11829:09/09 19:41:59.586891 00212138 C QRY start to create task, TID:0xb QID:0x2e20039735a00008, vgId:3 -11830:09/09 19:41:59.586919 00212137 C QRY subplan task create completed, TID:0xa QID:0x2e20039735a00008 -11831:09/09 19:41:59.586925 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to execTask, loopIdx:0 -11832:09/09 19:41:59.586928 00212137 C QRY TID:0xa QID:0x2e20039735a00008 execTask is launched -11833:09/09 19:41:59.586943 00212138 C QRY extract queried table list completed, 0 tables, elapsed time:0.00 ms TID:0xb QID:0x2e20039735a00008 -11834:09/09 19:41:59.586950 00212137 C TSD 0x7fa16001f930 create 1 tables scan-info, size:0.38 Kb, elapsed time:0.00 ms, TID:0xa QID:0x2e20039735a00008 -11835:09/09 19:41:59.586955 00212137 C TSD 0x7fa16001f930 total numOfTable:1, window:1410522119587 - 9223372036854775807, verRange:0 - 46 in this query TID:0xa QID:0x2e20039735a00008 -11836:09/09 19:41:59.586967 00212137 C TSD init fileset iterator, total files:1 TID:0xa QID:0x2e20039735a00008 -11837:09/09 19:41:59.586951 00212138 C QRY no table qualified for query, TID:0xb QID:0x2e20039735a00008lx -11838:09/09 19:41:59.586972 00212137 C TSD 0x7fa16001f930 file found fid:1997 for qrange:1410522119587-9223372036854775807, TID:0xa QID:0x2e20039735a00008 -11839:09/09 19:41:59.586979 00212137 C TSD load block of 1 tables completed, blocks:0 in 0 tables, stt-files:1, block-info-size:0.00 Kb, elapsed time:0.00 ms TID:0xa QID:0x2e20039735a00008 -11840:09/09 19:41:59.586983 00212137 C TSD reader: 0x7fa16001f930 resumed uid 0, numOfTable:1, in this query TID:0xa QID:0x2e20039735a00008 -11841:09/09 19:41:59.586986 00212137 C TSD seq load data blocks from stt files TID:0xa QID:0x2e20039735a00008 -11842:09/09 19:41:59.586989 00212137 C TSD init stt block reader, window:1410522119587-9223372036854775807, uid:8502546947039559767, TID:0xa QID:0x2e20039735a00008 -11843:09/09 19:41:59.587009 00212138 C QRY subplan task create completed, TID:0xb QID:0x2e20039735a00008 -11844:09/09 19:41:59.587018 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to execTask, loopIdx:0 -11845:09/09 19:41:59.587022 00212138 C QRY TID:0xb QID:0x2e20039735a00008 execTask is launched -11846:09/09 19:41:59.587040 00212137 C TSD TID:0xa QID:0x2e20039735a00008 load 1 statis blocks into buf, elapsed time:0.01ms -11847:09/09 19:41:59.587045 00212137 C TSD load the stt file blk info completed, elapsed time:0.02ms, TID:0xa QID:0x2e20039735a00008 -11848:09/09 19:41:59.587050 00212138 C TSD 0x7fa16401f900 create 0 tables scan-info, size:0.00 Kb, elapsed time:0.00 ms, TID:0xb QID:0x2e20039735a00008 -11849:09/09 19:41:59.587056 00212138 C TSD 0x7fa16401f900 total numOfTable:0, window:1410522119588 - 9223372036854775807, verRange:0 - 4 in this query TID:0xb QID:0x2e20039735a00008 -11850:09/09 19:41:59.587061 00212138 C TSD reader: 0x7fa16401f900 resumed uid 0, numOfTable:0, in this query TID:0xb QID:0x2e20039735a00008 -11851:09/09 19:41:59.587063 00212137 C TSD read stt block, total load:1, trigger by uid:8502546947039559767, stt-fileVer:1, last block index:0, entry:0, rows:42, uidRange:8502546947039559767-8502546947039559767 tsRange:1725878896277-1725878917534 0x7fa1600223d0, elapsed time:0.01 ms, TID:0xa QID:0x2e20039735a00008 -11853:09/09 19:41:59.587067 00212137 C TSD last block index list:0, -1, rowIndex:-1 TID:0xa QID:0x2e20039735a00008 -11854:09/09 19:41:59.587107 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11856:09/09 19:41:59.587118 00212138 C QRY TID:0xb QID:0x2e20039735a00008 task suspended, 0 rows in 0 blocks returned, total:0 rows, in sinkNode:0, elapsed:0.00 ms -11857:09/09 19:41:59.587124 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 qExecTask end with empty res, useconds:0 -11858:09/09 19:41:59.587131 00212137 C TSD 0x7fa16001f930 uid:8502546947039559767, no data in mem, TID:0xa QID:0x2e20039735a00008 -11859:09/09 19:41:59.587136 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to handle event at phase POST_QUERY -11860:09/09 19:41:59.587139 00212137 C TSD 0x7fa16001f930 uid:8502546947039559767, no data in imem, TID:0xa QID:0x2e20039735a00008 -11861:09/09 19:41:59.587166 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status updated from EXECUTING to PARTIAL_SUCCEED -11862:09/09 19:41:59.587172 00212137 C TSD init stt block reader completed, elapsed time:183us TID:0xa QID:0x2e20039735a00008 -11863:09/09 19:41:59.587178 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11864:09/09 19:41:59.587179 00212138 C RPC conn 0x7fa218014af0 start to send resp (1/2), gtid:0x2e20039735a00008:0x26f31d6973500026 -11865:09/09 19:41:59.587198 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11866:09/09 19:41:59.587203 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11867:09/09 19:41:59.587206 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11868:09/09 19:41:59.587207 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 query msg rsped, handle:0x7fa218021f60, code:0 - success -11869:09/09 19:41:59.587215 00212138 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 end to handle event at phase POST_QUERY, code:0 - success -11870:09/09 19:41:59.587220 00212138 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processQuery end, node:0x7fa24cfe7f50, code:0 -11871:09/09 19:41:59.587223 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11872:09/09 19:41:59.587228 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11873:09/09 19:41:59.587232 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11876:09/09 19:41:59.587308 00211996 C RPC DND-S conn 0x7fa218014af0 query-rsp is sent to 127.0.0.1:37174, local info:127.0.0.1:6100, len:130, seqNum:16, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 -11878:09/09 19:41:59.587326 00211996 C RPC DND-S conn 0x7fa218014af0 msg already send out, seqNum:16, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 -11879:09/09 19:41:59.587252 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11880:09/09 19:41:59.587507 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11881:09/09 19:41:59.587545 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11882:09/09 19:41:59.587554 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11883:09/09 19:41:59.587580 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11884:09/09 19:41:59.587608 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11885:09/09 19:41:59.587635 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11886:09/09 19:41:59.587663 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11887:09/09 19:41:59.587690 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11888:09/09 19:41:59.587719 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11889:09/09 19:41:59.587745 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11890:09/09 19:41:59.587781 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11891:09/09 19:41:59.587828 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11892:09/09 19:41:59.587856 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11893:09/09 19:41:59.587883 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11894:09/09 19:41:59.587910 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11895:09/09 19:41:59.587937 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11896:09/09 19:41:59.587964 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11897:09/09 19:41:59.587990 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11898:09/09 19:41:59.588034 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11899:09/09 19:41:59.588061 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11900:09/09 19:41:59.588087 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11901:09/09 19:41:59.588114 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11902:09/09 19:41:59.588139 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11903:09/09 19:41:59.588168 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11904:09/09 19:41:59.588176 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11905:09/09 19:41:59.588202 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11906:09/09 19:41:59.588228 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11907:09/09 19:41:59.588254 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11908:09/09 19:41:59.588298 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11909:09/09 19:41:59.588325 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11910:09/09 19:41:59.588351 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11911:09/09 19:41:59.588377 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11912:09/09 19:41:59.588385 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11913:09/09 19:41:59.588409 00212137 C TSD no more last block qualified, uid:8502546947039559767, stt-file block:0, TID:0xa QID:0x2e20039735a00008 -11914:09/09 19:41:59.588415 00212137 C TSD ERROR failed to exec stt-file nextIter, lino:0, code:success, TID:0xa QID:0x2e20039735a00008 -11915:09/09 19:41:59.588444 00212137 C TSD 0x7fa16001f930 uid:8502546947039559767, composed data block created, brange:1725878896277-1725878917534 rows:42, elapsed time:1.27 ms TID:0xa QID:0x2e20039735a00008 -11916:09/09 19:41:59.588470 00212137 C QRY retrieve table meta from cache:1, hit:0 miss:1, TID:0xa QID:0x2e20039735a00008 -11917:09/09 19:41:59.588498 00212137 C TSD seq load data blocks from stt files TID:0xa QID:0x2e20039735a00008 -11918:09/09 19:41:59.588503 00212137 C TSD seq load data blocks from cache, TID:0xa QID:0x2e20039735a00008 -11921:09/09 19:41:59.588518 00212137 C QRY TID:0xa QID:0x2e20039735a00008 task suspended, 42 rows in 1 blocks returned, total:42 rows, in sinkNode:0, elapsed:1.59 ms -11922:09/09 19:41:59.588535 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 data put into sink, rows:42, continueExecTask:1 -11923:09/09 19:41:59.588539 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 qExecTask done, useconds:1587 -11924:09/09 19:41:59.588542 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to handle event at phase POST_QUERY -11925:09/09 19:41:59.588549 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status updated from EXECUTING to PARTIAL_SUCCEED -11926:09/09 19:41:59.588558 00212137 C RPC conn 0x7fa210002100 start to send resp (1/2), gtid:0x2e20039735a00008:0x26f31d6973500025 -11927:09/09 19:41:59.588587 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 query msg rsped, handle:0x7fa210010ec0, code:0 - success -11928:09/09 19:41:59.588594 00212137 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 end to handle event at phase POST_QUERY, code:0 - success -11930:09/09 19:41:59.588600 00212137 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processQuery end, node:0x7fa24d7e8f50, code:0 -11932:09/09 19:41:59.588608 00211994 C RPC DND-S conn 0x7fa210002100 query-rsp is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:130, seqNum:15, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 -11934:09/09 19:41:59.588616 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:15, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 -11935:09/09 19:41:59.631192 00211994 C RPC DND-S conn 0x7fa210002100 merge-query received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:595, cost:80us, seqNum:16, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 -11936:09/09 19:41:59.631228 00211994 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 prerocessQuery start, handle:0x7fa210010ec0, SQL:select * from test.sp; -11938:09/09 19:41:59.631255 00211994 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status added, newStatus:INIT -11939:09/09 19:41:59.631260 00211994 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 prerocessQuery end, handle:0x7fa210010ec0, code:0 -11943:09/09 19:41:59.631349 00212139 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processQuery start, node:0x7fa24c7e6f50, type:merge-query, compress:0, handle:0x7fa210010ec0, SQL:select * from test.sp; -11944:09/09 19:41:59.631367 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to handle event at phase PRE_QUERY -11945:09/09 19:41:59.631378 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status updated from INIT to EXECUTING -11946:09/09 19:41:59.631382 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 end to handle event at phase PRE_QUERY, code:success -11947:09/09 19:41:59.631410 00212139 C QRY start to create task, TID:0x9 QID:0x2e20039735a00008, vgId:2 -11948:09/09 19:41:59.631435 00212139 C QRY subplan task create completed, TID:0x9 QID:0x2e20039735a00008 -11949:09/09 19:41:59.631439 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to execTask, loopIdx:0 -11950:09/09 19:41:59.631443 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 execTask is launched -11951:09/09 19:41:59.631450 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 build fetch msg and send to vgId:3, ep:localhost, taskId:0xb, execId:0, 0x7fa158002f60, 0/2 -11955:09/09 19:41:59.631501 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 build fetch msg and send to vgId:2, ep:localhost, taskId:0xa, execId:0, 0x7fa158002f60, 1/2 -11960:09/09 19:41:59.631527 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 send all fetch requests to 2 sources completed, elapsed:0.08ms -11961:09/09 19:41:59.631554 00212139 C QRY prepare wait for ready, 0x7fa158002f60, TID:0x9 QID:0x2e20039735a00008 -11974:09/09 19:41:59.631693 00212158 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processFetch start, node:0x7fa288001640, handle:0x7fa210021de0 -11975:09/09 19:41:59.631702 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to handle event at phase PRE_FETCH -11976:09/09 19:41:59.631709 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 end to handle event at phase PRE_FETCH, code:success -11977:09/09 19:41:59.631714 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 no more data in sink and query end, fetched blocks 0 rows 0 -11978:09/09 19:41:59.631721 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status updated from PARTIAL_SUCCEED to SUCCEED -11979:09/09 19:41:59.631725 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 start to handle event at phase POST_FETCH -11980:09/09 19:41:59.631728 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 end to handle event at phase POST_FETCH, code:0 - success -11982:09/09 19:41:59.631756 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 fetch rsp send, msgType:fetch-rsp, handle:0x7fa210021de0, code:0 - success, dataLen:0 -11983:09/09 19:41:59.631761 00212158 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processFetch end, node:0x7fa288001640, code:0 -11990:09/09 19:41:59.631932 00211999 C QRY TID:0x9 QID:0x2e20039735a00008 fetch rsp received, index:0, blocks:0, rows:0, 0x7fa158002f60 -11993:09/09 19:41:59.631972 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 vgId:3, taskId:0xb execId:0 index:0 completed, rowsOfSource:0, totalRows:0, try next 1/2 -11994:09/09 19:41:59.631993 00212139 C QRY prepare wait for ready, 0x7fa158002f60, TID:0x9 QID:0x2e20039735a00008 -11995:09/09 19:41:59.632005 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processFetch start, node:0x7fa290001630, handle:0x7fa210021de0 -11996:09/09 19:41:59.632013 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to handle event at phase PRE_FETCH -11997:09/09 19:41:59.632018 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 end to handle event at phase PRE_FETCH, code:success -11999:09/09 19:41:59.632025 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 there are data in sink, dataLength:746 -12000:09/09 19:41:59.632029 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task all data fetched and done, fetched blocks 1 rows 42 -12001:09/09 19:41:59.632033 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status updated from PARTIAL_SUCCEED to SUCCEED -12002:09/09 19:41:59.632036 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 start to handle event at phase POST_FETCH -12003:09/09 19:41:59.632038 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 end to handle event at phase POST_FETCH, code:0 - success -12005:09/09 19:41:59.632063 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 fetch rsp send, msgType:fetch-rsp, handle:0x7fa210021de0, code:0 - success, dataLen:754 -12006:09/09 19:41:59.632068 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processFetch end, node:0x7fa290001630, code:0 -12013:09/09 19:41:59.632150 00211999 C QRY TID:0x9 QID:0x2e20039735a00008 fetch rsp received, index:1, blocks:1, rows:42, 0x7fa158002f60 -12015:09/09 19:41:59.632191 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 fetch msg rsp from vgId:2, taskId:0xa execId:0 index:1 completed, blocks:1, numOfRows:42, rowsOfSource:42, totalRows:42, total:0.74 Kb, try next 2/2 -12016:09/09 19:41:59.632206 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 all 2 sources are exhausted, total rows: 42, 0.74 Kb, elapsed:0.69 ms -12017:09/09 19:41:59.632212 00212139 C QRY TID:0x9 QID:0x2e20039735a00008 task suspended, 42 rows in 1 blocks returned, total:42 rows, in sinkNode:0, elapsed:0.77 ms -12018:09/09 19:41:59.632219 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 data put into sink, rows:42, continueExecTask:1 -12019:09/09 19:41:59.632222 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 qExecTask done, useconds:766 -12020:09/09 19:41:59.632226 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to handle event at phase POST_QUERY -12021:09/09 19:41:59.632238 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status updated from EXECUTING to PARTIAL_SUCCEED -12022:09/09 19:41:59.632246 00212139 C RPC conn 0x7fa210002100 start to send resp (1/2), gtid:0x2e20039735a00008:0x26f31d6973500027 -12023:09/09 19:41:59.632271 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 query msg rsped, handle:0x7fa210010ec0, code:0 - success -12024:09/09 19:41:59.632277 00212139 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 end to handle event at phase POST_QUERY, code:0 - success -12025:09/09 19:41:59.632282 00212139 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processQuery end, node:0x7fa24c7e6f50, code:0 -12028:09/09 19:41:59.632295 00211994 C RPC DND-S conn 0x7fa210002100 merge-query-rsp is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:111, seqNum:16, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 -12030:09/09 19:41:59.632333 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:16, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 -12031:09/09 19:41:59.632825 00211994 C RPC DND-S conn 0x7fa210002100 merge-fetch received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:44, cost:54us, seqNum:17, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500028 -12032:09/09 19:41:59.632870 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processFetch start, node:0x7fa290001630, handle:0x7fa210010ec0 -12033:09/09 19:41:59.632878 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to handle event at phase PRE_FETCH -12034:09/09 19:41:59.632882 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 end to handle event at phase PRE_FETCH, code:success -12036:09/09 19:41:59.632887 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 there are data in sink, dataLength:746 -12037:09/09 19:41:59.632890 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task all data fetched and done, fetched blocks 1 rows 42 -12038:09/09 19:41:59.632894 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status updated from PARTIAL_SUCCEED to SUCCEED -12039:09/09 19:41:59.632896 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 start to handle event at phase POST_FETCH -12040:09/09 19:41:59.632899 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 end to handle event at phase POST_FETCH, code:0 - success -12041:09/09 19:41:59.632902 00212159 C RPC conn 0x7fa210002100 start to send resp (1/2), gtid:0x2e20039735a00008:0x26f31d6973500028 -12042:09/09 19:41:59.632921 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 fetch rsp send, msgType:merge-fetch-rsp, handle:0x7fa210010ec0, code:0 - success, dataLen:754 -12043:09/09 19:41:59.632925 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processFetch end, node:0x7fa290001630, code:0 -12046:09/09 19:41:59.632944 00211994 C RPC DND-S conn 0x7fa210002100 merge-fetch-rsp is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:1110, seqNum:17, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500028 -12048:09/09 19:41:59.632984 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:17, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500028 -12049:09/09 19:41:59.633734 00211994 C RPC DND-S conn 0x7fa210002100 drop-task received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:48, cost:49us, seqNum:18, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500029 -12050:09/09 19:41:59.633780 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processDrop start, node:0x7fa290001630, handle:0x7fa210010ec0 -12051:09/09 19:41:59.633805 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task status dropped -12053:09/09 19:41:59.633842 00211996 C RPC DND-S conn 0x7fa218014af0 drop-task received from 127.0.0.1:37174, local info:127.0.0.1:6100, len:48, cost:43us, seqNum:17, qid:22, gtid:0x2e20039735a00008:0x26f31d697350002b -12054:09/09 19:41:59.633842 00212159 C QRY TID:0x9 QID:0x2e20039735a00008 execTask completed, numOfRows:42 -12055:09/09 19:41:59.633853 00212159 C QRY TID:0x9 QID:0x2e20039735a00008 :cost summary: idle in queue:0.03 ms, elapsed time:0.77 ms -12057:09/09 19:41:59.633878 00212158 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processDrop start, node:0x7fa288001640, handle:0x7fa218021f60 -12058:09/09 19:41:59.633892 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task status dropped -12059:09/09 19:41:59.633859 00212159 C QRY TID:0x9 QID:0x2e20039735a00008 execTask is freed -12063:09/09 19:41:59.633914 00211994 C RPC DND-S conn 0x7fa210002100 task-release is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:91, seqNum:0, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 -12065:09/09 19:41:59.633926 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task ctx dropped -12066:09/09 19:41:59.633928 00212159 C QRY QID:0x2e20039735a00008,TID:0x9,EID:0 task is dropped -12067:09/09 19:41:59.633926 00212158 C QRY TID:0xb QID:0x2e20039735a00008 execTask completed, numOfRows:0 -12068:09/09 19:41:59.633932 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0x9,EID:0 processDrop end, node:0x7fa290001630, code:0 -12069:09/09 19:41:59.633935 00212158 C QRY TID:0xb QID:0x2e20039735a00008 :cost summary: idle:0.12 ms, elapsed time:0.00 ms, extract tableList:0.00 ms, createGroupIdMap:0.00 ms, total blocks:0, load block SMA:0, load data block:0, total rows:0, check rows:0 -12070:09/09 19:41:59.633942 00212158 C QRY TID:0xb QID:0x2e20039735a00008 execTask is freed -12073:09/09 19:41:59.633961 00211996 C RPC DND-S conn 0x7fa218014af0 task-release is sent to 127.0.0.1:37174, local info:127.0.0.1:6100, len:91, seqNum:0, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 -12074:09/09 19:41:59.633961 00212158 C TSD 0x7fa16401f900 :io-cost summary: head-file:0, head-file time:0.00 ms, SMA:0 SMA-time:0.00 ms, fileBlocks:0, fileBlocks-load-time:0.00 ms, build in-memory-block-time:0.00 ms, sttBlocks:0, sttBlocks-time:0.00 ms, sttStatisBlock:0, stt-statis-Block-time:0.00 ms, composed-blocks:0, composed-blocks-time:0.00ms, STableBlockScanInfo size:0.00 Kb, createTime:0.00 ms,createSkylineIterTime:0.00 ms, initSttBlockReader:0.00ms, TID:0xb QID:0x2e20039735a00008 -12076:09/09 19:41:59.633976 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:0, qid:23, gtid:0x2e20039735a00008:0x26f31d6973500027 -12079:09/09 19:41:59.633989 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task ctx dropped -12080:09/09 19:41:59.633991 00212158 C QRY QID:0x2e20039735a00008,TID:0xb,EID:0 task is dropped -12081:09/09 19:41:59.633991 00211994 C RPC DND-S conn 0x7fa210002100 drop-task received from 127.0.0.1:37180, local info:127.0.0.1:6100, len:48, cost:257us, seqNum:19, qid:21, gtid:0x2e20039735a00008:0x26f31d697350002a -12083:09/09 19:41:59.633995 00212158 C QRY QW:0x7fa2882818e0 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xb,EID:0 processDrop end, node:0x7fa288001640, code:0 -12084:09/09 19:41:59.634004 00211996 C RPC DND-S conn 0x7fa218014af0 msg already send out, seqNum:0, qid:22, gtid:0x2e20039735a00008:0x26f31d6973500026 -12085:09/09 19:41:59.634046 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processDrop start, node:0x7fa290001630, handle:0x7fa210010ec0 -12086:09/09 19:41:59.634059 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task status dropped -12088:09/09 19:41:59.634091 00212159 C QRY TID:0xa QID:0x2e20039735a00008 execTask completed, numOfRows:42 -12089:09/09 19:41:59.634097 00212159 C QRY TID:0xa QID:0x2e20039735a00008 :cost summary: idle:0.09 ms, elapsed time:1.59 ms, extract tableList:0.00 ms, createGroupIdMap:0.01 ms, total blocks:1, load block SMA:0, load data block:1, total rows:42, check rows:42 -12090:09/09 19:41:59.634105 00212159 C QRY TID:0xa QID:0x2e20039735a00008 execTask is freed -12093:09/09 19:41:59.634123 00211994 C RPC DND-S conn 0x7fa210002100 task-release is sent to 127.0.0.1:37180, local info:127.0.0.1:6100, len:91, seqNum:0, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 -12094:09/09 19:41:59.634143 00212159 C TSD 0x7fa16001f930 :io-cost summary: head-file:0, head-file time:0.00 ms, SMA:0 SMA-time:0.00 ms, fileBlocks:1, fileBlocks-load-time:0.00 ms, build in-memory-block-time:0.00 ms, sttBlocks:1, sttBlocks-time:0.01 ms, sttStatisBlock:1, stt-statis-Block-time:0.01 ms, composed-blocks:1, composed-blocks-time:1.27ms, STableBlockScanInfo size:0.38 Kb, createTime:0.00 ms,createSkylineIterTime:0.00 ms, initSttBlockReader:0.18ms, TID:0xa QID:0x2e20039735a00008 -12096:09/09 19:41:59.634157 00211994 C RPC DND-S conn 0x7fa210002100 msg already send out, seqNum:0, qid:21, gtid:0x2e20039735a00008:0x26f31d6973500025 -12099:09/09 19:41:59.634179 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task ctx dropped -12100:09/09 19:41:59.634181 00212159 C QRY QID:0x2e20039735a00008,TID:0xa,EID:0 task is dropped -12101:09/09 19:41:59.634184 00212159 C QRY QW:0x7fa2901c0b60 SID:0x3034663031623866,QID:0x2e20039735a00008,TID:0xa,EID:0 processDrop end, node:0x7fa290001630, code:0 diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 5950df95b8..9131d29f30 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -1881,7 +1881,6 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { taosMemoryFree(tEpSet); rpcFreeCont(pMsg->pCont); destroySendMsgInfo(pMsg->info.ahandle); - taosMemoryFree(tEpSet); return; } arg->msg = *pMsg; @@ -1921,19 +1920,19 @@ TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, cons return NULL; } -//TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, const char* pass, int passLen, -// const char* db, int dbLen, uint16_t port) { -// char ipStr[TSDB_EP_LEN] = {0}; -// char dbStr[TSDB_DB_NAME_LEN] = {0}; -// char userStr[TSDB_USER_LEN] = {0}; -// char passStr[TSDB_PASSWORD_LEN] = {0}; +// TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, const char* pass, int passLen, +// const char* db, int dbLen, uint16_t port) { +// char ipStr[TSDB_EP_LEN] = {0}; +// char dbStr[TSDB_DB_NAME_LEN] = {0}; +// char userStr[TSDB_USER_LEN] = {0}; +// char passStr[TSDB_PASSWORD_LEN] = {0}; // -// tstrncpy(ipStr, ip, TMIN(TSDB_EP_LEN - 1, ipLen)); -// tstrncpy(userStr, user, TMIN(TSDB_USER_LEN - 1, userLen)); -// tstrncpy(passStr, pass, TMIN(TSDB_PASSWORD_LEN - 1, passLen)); -// tstrncpy(dbStr, db, TMIN(TSDB_DB_NAME_LEN - 1, dbLen)); -// return taos_connect(ipStr, userStr, passStr, dbStr, port); -//} +// tstrncpy(ipStr, ip, TMIN(TSDB_EP_LEN - 1, ipLen)); +// tstrncpy(userStr, user, TMIN(TSDB_USER_LEN - 1, userLen)); +// tstrncpy(passStr, pass, TMIN(TSDB_PASSWORD_LEN - 1, passLen)); +// tstrncpy(dbStr, db, TMIN(TSDB_DB_NAME_LEN - 1, dbLen)); +// return taos_connect(ipStr, userStr, passStr, dbStr, port); +// } void doSetOneRowPtr(SReqResultInfo* pResultInfo) { for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { @@ -2301,7 +2300,8 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int (void)snprintf(varDataVal(dst), TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE, "%.9lf", jsonVd); varDataSetLen(dst, strlen(varDataVal(dst))); } else if (jsonInnerType == TSDB_DATA_TYPE_BOOL) { - (void)snprintf(varDataVal(dst), TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE, "%s", (*((char*)jsonInnerData) == 1) ? "true" : "false"); + (void)snprintf(varDataVal(dst), TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE, "%s", + (*((char*)jsonInnerData) == 1) ? "true" : "false"); varDataSetLen(dst, strlen(varDataVal(dst))); } else { tscError("doConvertJson error: invalid type:%d", jsonInnerType); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index d67e908e2a..a7c24f3fae 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -495,6 +495,10 @@ bool uvConnMayGetUserInfo(SSvrConn* pConn, STransMsgHead** ppHead, int32_t* msgL int32_t len = *msgLen; if (pHead->withUserInfo) { STransMsgHead* tHead = taosMemoryCalloc(1, len - sizeof(pInst->user)); + if (tHead == NULL) { + tError("conn %p failed to get user info since %s", pConn, tstrerror(terrno)); + return false; + } memcpy((char*)tHead, (char*)pHead, TRANS_MSG_OVERHEAD); memcpy((char*)tHead + TRANS_MSG_OVERHEAD, (char*)pHead + TRANS_MSG_OVERHEAD + sizeof(pInst->user), len - sizeof(STransMsgHead) - sizeof(pInst->user)); @@ -531,6 +535,13 @@ static bool uvHandleReq(SSvrConn* pConn) { if (uvConnMayGetUserInfo(pConn, &pHead, &msgLen) == true) { tDebug("%s conn %p get user info", transLabel(pInst), pConn); + } else { + if (pConn->userInited == 0) { + taosMemoryFree(pHead); + tDebug("%s conn %p failed get user info since %s", transLabel(pInst), pConn, tstrerror(terrno)); + return false; + } + tDebug("%s conn %p no need get user info", transLabel(pInst), pConn); } if (resetBuf == 0) { diff --git a/source/util/src/terror.c b/source/util/src/terror.c index b7835dc580..80d95252f9 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -55,13 +55,13 @@ 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") -TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_IN_PROCESS, "rpc async in process") -TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NO_STATE, "rpc no state") -TAOS_DEFINE_ERROR(TSDB_CODE_RPC_STATE_DROPED, "rpc state already dropped") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_MODULE_QUIT, "rpc async module already quit") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ASYNC_IN_PROCESS, "rpc async in process") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NO_STATE, "rpc no state") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_STATE_DROPED, "rpc state already dropped") //common & util TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized") diff --git a/source/util/src/theap.c b/source/util/src/theap.c index a5a71def50..600bc2b998 100644 --- a/source/util/src/theap.c +++ b/source/util/src/theap.c @@ -21,7 +21,6 @@ size_t heapSize(Heap* heap) { return heap->nelts; } Heap* heapCreate(HeapCompareFn fn) { Heap* heap = taosMemoryCalloc(1, sizeof(Heap)); if (heap == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -226,10 +225,11 @@ void destroyPriorityQueue(PriorityQueue* pq) { static size_t pqParent(size_t i) { return (--i) >> 1; /* (i - 1) / 2 */ } static size_t pqLeft(size_t i) { return (i << 1) | 1; /* i * 2 + 1 */ } static size_t pqRight(size_t i) { return (++i) << 1; /* (i + 1) * 2 */ } -static void pqSwapPQNode(PriorityQueueNode* a, PriorityQueueNode* b) { - void* tmp = a->data; - a->data = b->data; - b->data = tmp; + +static void pqSwapPQNode(PriorityQueueNode* a, PriorityQueueNode* b) { + void* tmp = a->data; + a->data = b->data; + b->data = tmp; } #define pqContainerGetEle(pq, i) ((PriorityQueueNode*)taosArrayGet((pq)->container, (i))) diff --git a/sql0 b/sql0 deleted file mode 100644 index 02a6f5d7fb..0000000000 --- a/sql0 +++ /dev/null @@ -1,140 +0,0 @@ -974:09/09 18:52:59.433846 00166866 C TSC 0x6 new Request from connObj:0x2, current:1, app current:1, total:5, reqId:0x987bae6a58a90008 975:09/09 18:52:59.433871 00166866 C TSC 0x6 SQL: select * from test.sp;, reqId:0x987bae6a58a90008 -977:09/09 18:52:59.433972 00166866 C QRY QID:0x987bae6a58a90008 the 0th task type [get db vgroup] initialized, dbFName:1.test -978:09/09 18:52:59.433978 00166866 C QRY QID:0x987bae6a58a90008 the 1th task type [bget table meta] initialized, dbNum:1, tbNum:1 -979:09/09 18:52:59.433982 00166866 C QRY QID:0x987bae6a58a90008 the 2th task type [bget table hash] initialized, dbNum:1, tbNum:1 -980:09/09 18:52:59.433986 00166866 C QRY QID:0x987bae6a58a90008 the 3th task type [get user] initialized, user:root -981:09/09 18:52:59.433991 00166866 C QRY QID:0x987bae6a58a90008, jobId: 0x5 initialized, task num 5, forceUpdate 0, elapsed time:0.03 ms -982:09/09 18:52:59.434002 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [0th] task -985:09/09 18:52:59.434031 00166866 C QRY QID:0x987bae6a58a90008 task 0 end with res success -986:09/09 18:52:59.434036 00166866 C QRY QID:0x987bae6a58a90008 task done: 1, total: 5 -987:09/09 18:52:59.434039 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [1th] task -990:09/09 18:52:59.434053 00166866 C QRY QID:0x987bae6a58a90008 task 1 end with res success -991:09/09 18:52:59.434056 00166866 C QRY QID:0x987bae6a58a90008 task done: 2, total: 5 -992:09/09 18:52:59.434059 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [2th] task -995:09/09 18:52:59.434072 00166866 C QRY QID:0x987bae6a58a90008 task 2 end with res success -996:09/09 18:52:59.434075 00166866 C QRY QID:0x987bae6a58a90008 task done: 3, total: 5 -997:09/09 18:52:59.434078 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [3th] task -1000:09/09 18:52:59.434090 00166866 C QRY QID:0x987bae6a58a90008 task 3 end with res success -1001:09/09 18:52:59.434104 00166866 C QRY QID:0x987bae6a58a90008 task done: 4, total: 5 -1002:09/09 18:52:59.434108 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [4th] task -1003:09/09 18:52:59.434114 00166866 C QRY QID:0x987bae6a58a90008 task 4 end with res success -1004:09/09 18:52:59.434170 00166842 C QRY QID:0x987bae6a58a90008 ctg start to call user cb with rsp success -1005:09/09 18:52:59.434187 00166842 C QRY 0x6 start to semantic analysis, reqId:0x987bae6a58a90008 -1006:09/09 18:52:59.434337 00166842 C TSC 0x987bae6a58a90008 vnode policy, use vnode list, num:2 -1008:09/09 18:52:59.434346 00166842 C QRY QID:0x987bae6a58a90008 set job levelIdx to 1 -1009:09/09 18:52:59.434352 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 task initialized, max times 6:6 -1010:09/09 18:52:59.434355 00166842 C QRY QID:0x987bae6a58a90008 level 0 initialized, taskNum:1 -1011:09/09 18:52:59.434358 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 task initialized, max times 6:12 -1012:09/09 18:52:59.434360 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 task initialized, max times 6:12 -1013:09/09 18:52:59.434361 00166842 C QRY QID:0x987bae6a58a90008 level 1 initialized, taskNum:2 -1014:09/09 18:52:59.434363 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 children info, the 0 child TID 0x7 -1015:09/09 18:52:59.434365 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 children info, the 1 child TID 0x8 -1016:09/09 18:52:59.434366 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 level:0, parentNum:0, childNum:2 -1017:09/09 18:52:59.434367 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 parents info, the 0 parent TID 0x6 -1018:09/09 18:52:59.434368 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 level:1, parentNum:1, childNum:0 -1019:09/09 18:52:59.434369 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 parents info, the 0 parent TID 0x6 -1020:09/09 18:52:59.434371 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 level:1, parentNum:1, childNum:0 -1021:09/09 18:52:59.434373 00166842 C QRY QID:0x987bae6a58a90008 job refId:0x5 created -1023:09/09 18:52:59.434377 00166842 C QRY QID:0x987bae6a58a90008 job start EXEC operation -1024:09/09 18:52:59.434381 00166842 C QRY QID:0x987bae6a58a90008 job status updated from NULL to INIT -1025:09/09 18:52:59.434382 00166842 C QRY QID:0x987bae6a58a90008 job status updated from INIT to EXECUTING -1026:09/09 18:52:59.434383 00166842 C QRY QID:0x987bae6a58a90008 sch job refId 0x5 started -1027:09/09 18:52:59.434385 00166842 C QRY QID:0x987bae6a58a90008 job no need flow ctrl, totalTableNum:0 -1028:09/09 18:52:59.434410 00166842 C QRY QID:0x987bae6a58a90008 job exec done, job status:EXECUTING, jobId:0x5 -1029:09/09 18:52:59.434414 00166842 C QRY QID:0x987bae6a58a90008 job end EXEC operation with code success -1031:09/09 18:52:59.434417 00166842 C QRY QID:0x987bae6a58a90008 ctg end to call user cb -1032:09/09 18:52:59.434424 00166842 C QRY QID:0x987bae6a58a90008, ctg job 0x5 freed -1035:09/09 18:52:59.434456 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to launch REMOTE task, execId 0, retry 1 -1036:09/09 18:52:59.434458 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to launch REMOTE task, execId 0, retry 1 -1037:09/09 18:52:59.434484 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task added to execTask list, numOfTasks:1 -1038:09/09 18:52:59.434485 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task added to execTask list, numOfTasks:2 -1039:09/09 18:52:59.434503 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 use execNode in plan as candidate addr, numOfEps:1 -1040:09/09 18:52:59.434515 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 use execNode in plan as candidate addr, numOfEps:1 -1050:09/09 18:52:59.434576 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 target candidateIdx 0, epInUse 0/1 -1052:09/09 18:52:59.434588 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to send query msg to node[3,localhost,6100], pTrans:0x2, pHandle:0x11 -1054:09/09 18:52:59.434593 00166842 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65a4003330, gtid:0x987bae6a58a90008:0x31de1d66a580001d -1055:09/09 18:52:59.434595 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 req msg sent, type:769, query -1056:09/09 18:52:59.434597 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task execNode added, execId:0, handle:0x11 -1059:09/09 18:52:59.434605 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 target candidateIdx 0, epInUse 0/1 -1062:09/09 18:52:59.434666 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to send query msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x12 -1065:09/09 18:52:59.434672 00166843 C RPC TSC send request at thread:00166860, dst:localhost:6100, app:0x7f65a8006120, gtid:0x987bae6a58a90008:0x31de1d66a580001e -1066:09/09 18:52:59.434696 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 req msg sent, type:769, query -1068:09/09 18:52:59.434700 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task execNode added, execId:0, handle:0x12 -1077:09/09 18:52:59.434797 00166862 C RPC TSC conn 0x7f65bc000c40 query is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:14, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d -1089:09/09 18:52:59.434934 00166860 C RPC TSC conn 0x7f65d4000c40 query is sent to 127.0.0.1:6100, local info:127.0.0.1:57868, seq:9, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e -1107:09/09 18:52:59.480608 00166862 C RPC TSC conn 0x7f65bc000c40 query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:130, seq:14, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d -1108:09/09 18:52:59.480658 00166860 C RPC TSC conn 0x7f65d4000c40 query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57868, len:130, seq:9, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e -1111:09/09 18:52:59.480728 00166847 C TSC processMsgFromServer handle 0x11, message: query-rsp, size:39, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001d -1114:09/09 18:52:59.480779 00166847 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 handle updated to 0x11 for execId 0 -1115:09/09 18:52:59.480795 00166847 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 taskOnSuccess, status:EXECUTING -1116:09/09 18:52:59.480809 00166847 C QRY PLAN: QID:0x987bae6a58a90008 set subplan execution node, groupId:2 -1119:09/09 18:52:59.480832 00166847 C TSC processMsgFromServer handle 0x12, message: query-rsp, size:39, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001e -1122:09/09 18:52:59.480854 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 handle updated to 0x12 for execId 0 -1123:09/09 18:52:59.480863 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 taskOnSuccess, status:EXECUTING -1124:09/09 18:52:59.480868 00166847 C QRY PLAN: QID:0x987bae6a58a90008 set subplan execution node, groupId:2 -1125:09/09 18:52:59.480872 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 all 2 children task done, start to launch parent task 0x6 -1129:09/09 18:52:59.480921 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to launch REMOTE task, execId 0, retry 1 -1130:09/09 18:52:59.480927 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task added to execTask list, numOfTasks:3 -1131:09/09 18:52:59.480959 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 target candidateIdx 0, epInUse 0/1 -1133:09/09 18:52:59.480982 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send merge-query msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 -1135:09/09 18:52:59.480998 00166847 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f6598006b80, gtid:0x987bae6a58a90008:0x31de1d66a580001f -1136:09/09 18:52:59.481028 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:771, merge-query -1137:09/09 18:52:59.481035 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task execNode added, execId:0, handle:0x13 -1143:09/09 18:52:59.481077 00166862 C RPC TSC conn 0x7f65bc000c40 merge-query is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:15, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f -1145:09/09 18:52:59.481938 00166862 C RPC TSC conn 0x7f65bc000c40 merge-query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:111, seq:15, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f -1147:09/09 18:52:59.481995 00166850 C TSC processMsgFromServer handle 0x13, message: merge-query-rsp, size:20, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001f -1150:09/09 18:52:59.482031 00166850 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 handle updated to 0x13 for execId 0 -1151:09/09 18:52:59.482042 00166850 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 taskOnSuccess, status:EXECUTING -1152:09/09 18:52:59.482049 00166850 C QRY QID:0x987bae6a58a90008 job status updated from EXECUTING to PARTIAL_SUCCEED -1153:09/09 18:52:59.482055 00166850 C QRY QID:0x987bae6a58a90008 execRes dumped, code: success -1154:09/09 18:52:59.482058 00166850 C QRY QID:0x987bae6a58a90008 sch start to invoke exec cb, code: success -1155:09/09 18:52:59.482062 00166850 C TSC 0x6 enter scheduler exec cb, code:success, reqId:0x987bae6a58a90008 -1162:09/09 18:52:59.482157 00166850 C QRY QID:0x987bae6a58a90008 sch end from exec cb, code: success -1168:09/09 18:52:59.482384 00166866 C QRY QID:0x987bae6a58a90008 job start FETCH operation -1169:09/09 18:52:59.482390 00166866 C QRY QID:0x987bae6a58a90008 job status updated from PARTIAL_SUCCEED to FETCHING -1170:09/09 18:52:59.482403 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send merge-fetch msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 -1172:09/09 18:52:59.482426 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65943151d0, gtid:0x987bae6a58a90008:0x31de1d66a5800020 -1173:09/09 18:52:59.482452 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:779, merge-fetch -1174:09/09 18:52:59.482460 00166866 C QRY QID:0x987bae6a58a90008 job end FETCH operation with code success -1178:09/09 18:52:59.482489 00166862 C RPC TSC conn 0x7f65bc000c40 merge-fetch is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:16, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800020 -1180:09/09 18:52:59.482714 00166862 C RPC TSC conn 0x7f65bc000c40 merge-fetch-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:1110, seq:16, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800020 -1182:09/09 18:52:59.482782 00166852 C TSC processMsgFromServer handle 0x13, message: merge-fetch-rsp, size:1019, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a5800020 -1185:09/09 18:52:59.482829 00166852 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 handle updated to 0x13 for execId 0 -1186:09/09 18:52:59.482835 00166852 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 got fetch rsp, rows:42, complete:1 -1187:09/09 18:52:59.482839 00166852 C QRY QID:0x987bae6a58a90008 job status updated from FETCHING to SUCCEED -1188:09/09 18:52:59.482842 00166852 C QRY QID:0x987bae6a58a90008 fetch done, totalRows:42 -1189:09/09 18:52:59.482845 00166852 C QRY QID:0x987bae6a58a90008 sch start to invoke fetch cb, code: success -1190:09/09 18:52:59.482848 00166852 C TSC 0x6 enter scheduler fetch cb, code:0 - success, reqId:0x987bae6a58a90008 -1191:09/09 18:52:59.482858 00166852 C TSC 0x6 fetch results, numOfRows:42 total Rows:42, complete:1, reqId:0x987bae6a58a90008 -1192:09/09 18:52:59.483360 00166852 C QRY QID:0x987bae6a58a90008 sch end from fetch cb, code: success -1196:09/09 18:52:59.483396 00166866 C TSC 0x987bae6a58a90008 taos_free_result start to free query -1198:09/09 18:52:59.483414 00166866 C QRY QID:0x987bae6a58a90008 start to free job 0x5, code:Query killed -1199:09/09 18:52:59.483419 00166866 C QRY QID:0x987bae6a58a90008 job status updated from SUCCEED to DROPPING -1200:09/09 18:52:59.483423 00166866 C QRY QID:0x987bae6a58a90008 job errCode updated to Query killed -1201:09/09 18:52:59.483426 00166866 C QRY QID:0x987bae6a58a90008 job failed with error Query killed -1202:09/09 18:52:59.483428 00166866 C QRY QID:0x987bae6a58a90008 job not in any operation, no need to post job res, status:DROPPING -1203:09/09 18:52:59.483432 00166866 C QRY QID:0x987bae6a58a90008 job removed from jobRef list, refId:0x5 -1205:09/09 18:52:59.483437 00166866 C QRY QID:0x987bae6a58a90008 begin to free sch job, refId:0x5, pointer:0x7f65a400d4a0 -1206:09/09 18:52:59.483449 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to send drop-task msg to node[3,localhost,6100], pTrans:0x2, pHandle:0x11 -1208:09/09 18:52:59.483462 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f6594302920, gtid:0x987bae6a58a90008:0x31de1d66a5800021 -1209:09/09 18:52:59.483487 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 req msg sent, type:783, drop-task -1210:09/09 18:52:59.483494 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to drop task's 0th execNode -1211:09/09 18:52:59.483498 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task has been dropped on 1 exec nodes -1212:09/09 18:52:59.483505 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send drop-task msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 -1214:09/09 18:52:59.483515 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65943031b0, gtid:0x987bae6a58a90008:0x31de1d66a5800022 -1215:09/09 18:52:59.483519 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:783, drop-task -1216:09/09 18:52:59.483521 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to drop task's 0th execNode -1217:09/09 18:52:59.483524 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task has been dropped on 1 exec nodes -1218:09/09 18:52:59.483528 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to send drop-task msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x12 -1220:09/09 18:52:59.483535 00166866 C RPC TSC send request at thread:00166860, dst:localhost:6100, app:0x7f659430e900, gtid:0x987bae6a58a90008:0x31de1d66a5800023 -1221:09/09 18:52:59.483560 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 req msg sent, type:783, drop-task -1222:09/09 18:52:59.483566 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to drop task's 0th execNode -1223:09/09 18:52:59.483570 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task has been dropped on 1 exec nodes -1226:09/09 18:52:59.483597 00166860 C RPC TSC conn 0x7f65d4000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57868, seq:10, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a5800023 -1228:09/09 18:52:59.483610 00166866 C QRY QID:0x987bae6a58a90008 sch job freed, refId:0x5, pointer:0x7f65a400d4a0 -1230:09/09 18:52:59.483622 00166866 C TSC 0x6 free Request from connObj: 0x2, reqId:0x987bae6a58a90008 elapsed:49.78 ms, current:0, app current:0 -1234:09/09 18:52:59.483739 00166862 C RPC TSC conn 0x7f65bc000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:17, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a5800021 -1236:09/09 18:52:59.483813 00166860 C RPC TSC conn 0x7f65d4000c40 receive release req, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e -1242:09/09 18:52:59.483854 00166862 C RPC TSC conn 0x7f65bc000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:18, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800022 -1246:09/09 18:52:59.484011 00166862 C RPC TSC conn 0x7f65bc000c40 receive release req, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d -1250:09/09 18:52:59.484124 00166862 C RPC TSC conn 0x7f65bc000c40 receive release req, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f diff --git a/sql1 b/sql1 deleted file mode 100644 index 6924fc9a2a..0000000000 --- a/sql1 +++ /dev/null @@ -1,141 +0,0 @@ -974:09/09 18:52:59.433846 00166866 C TSC 0x6 new Request from connObj:0x2, current:1, app current:1, total:5, reqId:0x987bae6a58a90008 -975:09/09 18:52:59.433871 00166866 C TSC 0x6 SQL: select * from test.sp;, reqId:0x987bae6a58a90008 -977:09/09 18:52:59.433972 00166866 C QRY QID:0x987bae6a58a90008 the 0th task type [get db vgroup] initialized, dbFName:1.test -978:09/09 18:52:59.433978 00166866 C QRY QID:0x987bae6a58a90008 the 1th task type [bget table meta] initialized, dbNum:1, tbNum:1 -979:09/09 18:52:59.433982 00166866 C QRY QID:0x987bae6a58a90008 the 2th task type [bget table hash] initialized, dbNum:1, tbNum:1 -980:09/09 18:52:59.433986 00166866 C QRY QID:0x987bae6a58a90008 the 3th task type [get user] initialized, user:root -981:09/09 18:52:59.433991 00166866 C QRY QID:0x987bae6a58a90008, jobId: 0x5 initialized, task num 5, forceUpdate 0, elapsed time:0.03 ms -982:09/09 18:52:59.434002 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [0th] task -985:09/09 18:52:59.434031 00166866 C QRY QID:0x987bae6a58a90008 task 0 end with res success -986:09/09 18:52:59.434036 00166866 C QRY QID:0x987bae6a58a90008 task done: 1, total: 5 -987:09/09 18:52:59.434039 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [1th] task -990:09/09 18:52:59.434053 00166866 C QRY QID:0x987bae6a58a90008 task 1 end with res success -991:09/09 18:52:59.434056 00166866 C QRY QID:0x987bae6a58a90008 task done: 2, total: 5 -992:09/09 18:52:59.434059 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [2th] task -995:09/09 18:52:59.434072 00166866 C QRY QID:0x987bae6a58a90008 task 2 end with res success -996:09/09 18:52:59.434075 00166866 C QRY QID:0x987bae6a58a90008 task done: 3, total: 5 -997:09/09 18:52:59.434078 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [3th] task -1000:09/09 18:52:59.434090 00166866 C QRY QID:0x987bae6a58a90008 task 3 end with res success -1001:09/09 18:52:59.434104 00166866 C QRY QID:0x987bae6a58a90008 task done: 4, total: 5 -1002:09/09 18:52:59.434108 00166866 C QRY QID:0x987bae6a58a90008 ctg launch [4th] task -1003:09/09 18:52:59.434114 00166866 C QRY QID:0x987bae6a58a90008 task 4 end with res success -1004:09/09 18:52:59.434170 00166842 C QRY QID:0x987bae6a58a90008 ctg start to call user cb with rsp success -1005:09/09 18:52:59.434187 00166842 C QRY 0x6 start to semantic analysis, reqId:0x987bae6a58a90008 -1006:09/09 18:52:59.434337 00166842 C TSC 0x987bae6a58a90008 vnode policy, use vnode list, num:2 -1008:09/09 18:52:59.434346 00166842 C QRY QID:0x987bae6a58a90008 set job levelIdx to 1 -1009:09/09 18:52:59.434352 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 task initialized, max times 6:6 -1010:09/09 18:52:59.434355 00166842 C QRY QID:0x987bae6a58a90008 level 0 initialized, taskNum:1 -1011:09/09 18:52:59.434358 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 task initialized, max times 6:12 -1012:09/09 18:52:59.434360 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 task initialized, max times 6:12 -1013:09/09 18:52:59.434361 00166842 C QRY QID:0x987bae6a58a90008 level 1 initialized, taskNum:2 -1014:09/09 18:52:59.434363 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 children info, the 0 child TID 0x7 -1015:09/09 18:52:59.434365 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 children info, the 1 child TID 0x8 -1016:09/09 18:52:59.434366 00166842 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:-1 level:0, parentNum:0, childNum:2 -1017:09/09 18:52:59.434367 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 parents info, the 0 parent TID 0x6 -1018:09/09 18:52:59.434368 00166842 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:-1 level:1, parentNum:1, childNum:0 -1019:09/09 18:52:59.434369 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 parents info, the 0 parent TID 0x6 -1020:09/09 18:52:59.434371 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:-1 level:1, parentNum:1, childNum:0 -1021:09/09 18:52:59.434373 00166842 C QRY QID:0x987bae6a58a90008 job refId:0x5 created -1023:09/09 18:52:59.434377 00166842 C QRY QID:0x987bae6a58a90008 job start EXEC operation -1024:09/09 18:52:59.434381 00166842 C QRY QID:0x987bae6a58a90008 job status updated from NULL to INIT -1025:09/09 18:52:59.434382 00166842 C QRY QID:0x987bae6a58a90008 job status updated from INIT to EXECUTING -1026:09/09 18:52:59.434383 00166842 C QRY QID:0x987bae6a58a90008 sch job refId 0x5 started -1027:09/09 18:52:59.434385 00166842 C QRY QID:0x987bae6a58a90008 job no need flow ctrl, totalTableNum:0 -1028:09/09 18:52:59.434410 00166842 C QRY QID:0x987bae6a58a90008 job exec done, job status:EXECUTING, jobId:0x5 -1029:09/09 18:52:59.434414 00166842 C QRY QID:0x987bae6a58a90008 job end EXEC operation with code success -1031:09/09 18:52:59.434417 00166842 C QRY QID:0x987bae6a58a90008 ctg end to call user cb -1032:09/09 18:52:59.434424 00166842 C QRY QID:0x987bae6a58a90008, ctg job 0x5 freed -1035:09/09 18:52:59.434456 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to launch REMOTE task, execId 0, retry 1 -1036:09/09 18:52:59.434458 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to launch REMOTE task, execId 0, retry 1 -1037:09/09 18:52:59.434484 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task added to execTask list, numOfTasks:1 -1038:09/09 18:52:59.434485 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task added to execTask list, numOfTasks:2 -1039:09/09 18:52:59.434503 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 use execNode in plan as candidate addr, numOfEps:1 -1040:09/09 18:52:59.434515 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 use execNode in plan as candidate addr, numOfEps:1 -1050:09/09 18:52:59.434576 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 target candidateIdx 0, epInUse 0/1 -1052:09/09 18:52:59.434588 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to send query msg to node[3,localhost,6100], pTrans:0x2, pHandle:0x11 -1054:09/09 18:52:59.434593 00166842 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65a4003330, gtid:0x987bae6a58a90008:0x31de1d66a580001d -1055:09/09 18:52:59.434595 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 req msg sent, type:769, query -1056:09/09 18:52:59.434597 00166842 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task execNode added, execId:0, handle:0x11 -1059:09/09 18:52:59.434605 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 target candidateIdx 0, epInUse 0/1 -1062:09/09 18:52:59.434666 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to send query msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x12 -1065:09/09 18:52:59.434672 00166843 C RPC TSC send request at thread:00166860, dst:localhost:6100, app:0x7f65a8006120, gtid:0x987bae6a58a90008:0x31de1d66a580001e -1066:09/09 18:52:59.434696 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 req msg sent, type:769, query -1068:09/09 18:52:59.434700 00166843 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task execNode added, execId:0, handle:0x12 -1077:09/09 18:52:59.434797 00166862 C RPC TSC conn 0x7f65bc000c40 query is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:14, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d -1089:09/09 18:52:59.434934 00166860 C RPC TSC conn 0x7f65d4000c40 query is sent to 127.0.0.1:6100, local info:127.0.0.1:57868, seq:9, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e -1107:09/09 18:52:59.480608 00166862 C RPC TSC conn 0x7f65bc000c40 query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:130, seq:14, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d -1108:09/09 18:52:59.480658 00166860 C RPC TSC conn 0x7f65d4000c40 query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57868, len:130, seq:9, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e -1111:09/09 18:52:59.480728 00166847 C TSC processMsgFromServer handle 0x11, message: query-rsp, size:39, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001d -1114:09/09 18:52:59.480779 00166847 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 handle updated to 0x11 for execId 0 -1115:09/09 18:52:59.480795 00166847 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 taskOnSuccess, status:EXECUTING -1116:09/09 18:52:59.480809 00166847 C QRY PLAN: QID:0x987bae6a58a90008 set subplan execution node, groupId:2 -1119:09/09 18:52:59.480832 00166847 C TSC processMsgFromServer handle 0x12, message: query-rsp, size:39, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001e -1122:09/09 18:52:59.480854 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 handle updated to 0x12 for execId 0 -1123:09/09 18:52:59.480863 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 taskOnSuccess, status:EXECUTING -1124:09/09 18:52:59.480868 00166847 C QRY PLAN: QID:0x987bae6a58a90008 set subplan execution node, groupId:2 -1125:09/09 18:52:59.480872 00166847 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 all 2 children task done, start to launch parent task 0x6 -1129:09/09 18:52:59.480921 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to launch REMOTE task, execId 0, retry 1 -1130:09/09 18:52:59.480927 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task added to execTask list, numOfTasks:3 -1131:09/09 18:52:59.480959 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 target candidateIdx 0, epInUse 0/1 -1133:09/09 18:52:59.480982 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send merge-query msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 -1135:09/09 18:52:59.480998 00166847 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f6598006b80, gtid:0x987bae6a58a90008:0x31de1d66a580001f -1136:09/09 18:52:59.481028 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:771, merge-query -1137:09/09 18:52:59.481035 00166847 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task execNode added, execId:0, handle:0x13 -1143:09/09 18:52:59.481077 00166862 C RPC TSC conn 0x7f65bc000c40 merge-query is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:15, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f -1145:09/09 18:52:59.481938 00166862 C RPC TSC conn 0x7f65bc000c40 merge-query-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:111, seq:15, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f -1147:09/09 18:52:59.481995 00166850 C TSC processMsgFromServer handle 0x13, message: merge-query-rsp, size:20, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a580001f -1150:09/09 18:52:59.482031 00166850 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 handle updated to 0x13 for execId 0 -1151:09/09 18:52:59.482042 00166850 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 taskOnSuccess, status:EXECUTING -1152:09/09 18:52:59.482049 00166850 C QRY QID:0x987bae6a58a90008 job status updated from EXECUTING to PARTIAL_SUCCEED -1153:09/09 18:52:59.482055 00166850 C QRY QID:0x987bae6a58a90008 execRes dumped, code: success -1154:09/09 18:52:59.482058 00166850 C QRY QID:0x987bae6a58a90008 sch start to invoke exec cb, code: success -1155:09/09 18:52:59.482062 00166850 C TSC 0x6 enter scheduler exec cb, code:success, reqId:0x987bae6a58a90008 -1162:09/09 18:52:59.482157 00166850 C QRY QID:0x987bae6a58a90008 sch end from exec cb, code: success -1168:09/09 18:52:59.482384 00166866 C QRY QID:0x987bae6a58a90008 job start FETCH operation -1169:09/09 18:52:59.482390 00166866 C QRY QID:0x987bae6a58a90008 job status updated from PARTIAL_SUCCEED to FETCHING -1170:09/09 18:52:59.482403 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send merge-fetch msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 -1172:09/09 18:52:59.482426 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65943151d0, gtid:0x987bae6a58a90008:0x31de1d66a5800020 -1173:09/09 18:52:59.482452 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:779, merge-fetch -1174:09/09 18:52:59.482460 00166866 C QRY QID:0x987bae6a58a90008 job end FETCH operation with code success -1178:09/09 18:52:59.482489 00166862 C RPC TSC conn 0x7f65bc000c40 merge-fetch is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:16, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800020 -1180:09/09 18:52:59.482714 00166862 C RPC TSC conn 0x7f65bc000c40 merge-fetch-rsp received from 127.0.0.1:6100, local info:127.0.0.1:57880, len:1110, seq:16, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800020 -1182:09/09 18:52:59.482782 00166852 C TSC processMsgFromServer handle 0x13, message: merge-fetch-rsp, size:1019, code: success, gtid: 0x987bae6a58a90008:0x31de1d66a5800020 -1185:09/09 18:52:59.482829 00166852 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 handle updated to 0x13 for execId 0 -1186:09/09 18:52:59.482835 00166852 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 got fetch rsp, rows:42, complete:1 -1187:09/09 18:52:59.482839 00166852 C QRY QID:0x987bae6a58a90008 job status updated from FETCHING to SUCCEED -1188:09/09 18:52:59.482842 00166852 C QRY QID:0x987bae6a58a90008 fetch done, totalRows:42 -1189:09/09 18:52:59.482845 00166852 C QRY QID:0x987bae6a58a90008 sch start to invoke fetch cb, code: success -1190:09/09 18:52:59.482848 00166852 C TSC 0x6 enter scheduler fetch cb, code:0 - success, reqId:0x987bae6a58a90008 -1191:09/09 18:52:59.482858 00166852 C TSC 0x6 fetch results, numOfRows:42 total Rows:42, complete:1, reqId:0x987bae6a58a90008 -1192:09/09 18:52:59.483360 00166852 C QRY QID:0x987bae6a58a90008 sch end from fetch cb, code: success -1196:09/09 18:52:59.483396 00166866 C TSC 0x987bae6a58a90008 taos_free_result start to free query -1198:09/09 18:52:59.483414 00166866 C QRY QID:0x987bae6a58a90008 start to free job 0x5, code:Query killed -1199:09/09 18:52:59.483419 00166866 C QRY QID:0x987bae6a58a90008 job status updated from SUCCEED to DROPPING -1200:09/09 18:52:59.483423 00166866 C QRY QID:0x987bae6a58a90008 job errCode updated to Query killed -1201:09/09 18:52:59.483426 00166866 C QRY QID:0x987bae6a58a90008 job failed with error Query killed -1202:09/09 18:52:59.483428 00166866 C QRY QID:0x987bae6a58a90008 job not in any operation, no need to post job res, status:DROPPING -1203:09/09 18:52:59.483432 00166866 C QRY QID:0x987bae6a58a90008 job removed from jobRef list, refId:0x5 -1205:09/09 18:52:59.483437 00166866 C QRY QID:0x987bae6a58a90008 begin to free sch job, refId:0x5, pointer:0x7f65a400d4a0 -1206:09/09 18:52:59.483449 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to send drop-task msg to node[3,localhost,6100], pTrans:0x2, pHandle:0x11 -1208:09/09 18:52:59.483462 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f6594302920, gtid:0x987bae6a58a90008:0x31de1d66a5800021 -1209:09/09 18:52:59.483487 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 req msg sent, type:783, drop-task -1210:09/09 18:52:59.483494 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 start to drop task's 0th execNode -1211:09/09 18:52:59.483498 00166866 C QRY QID:0x987bae6a58a90008,TID:0x8,EID:0 task has been dropped on 1 exec nodes -1212:09/09 18:52:59.483505 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to send drop-task msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x13 -1214:09/09 18:52:59.483515 00166866 C RPC TSC send request at thread:00166862, dst:localhost:6100, app:0x7f65943031b0, gtid:0x987bae6a58a90008:0x31de1d66a5800022 -1215:09/09 18:52:59.483519 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 req msg sent, type:783, drop-task -1216:09/09 18:52:59.483521 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 start to drop task's 0th execNode -1217:09/09 18:52:59.483524 00166866 C QRY QID:0x987bae6a58a90008,TID:0x6,EID:0 task has been dropped on 1 exec nodes -1218:09/09 18:52:59.483528 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to send drop-task msg to node[2,localhost,6100], pTrans:0x2, pHandle:0x12 -1220:09/09 18:52:59.483535 00166866 C RPC TSC send request at thread:00166860, dst:localhost:6100, app:0x7f659430e900, gtid:0x987bae6a58a90008:0x31de1d66a5800023 -1221:09/09 18:52:59.483560 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 req msg sent, type:783, drop-task -1222:09/09 18:52:59.483566 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 start to drop task's 0th execNode -1223:09/09 18:52:59.483570 00166866 C QRY QID:0x987bae6a58a90008,TID:0x7,EID:0 task has been dropped on 1 exec nodes -1226:09/09 18:52:59.483597 00166860 C RPC TSC conn 0x7f65d4000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57868, seq:10, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a5800023 -1228:09/09 18:52:59.483610 00166866 C QRY QID:0x987bae6a58a90008 sch job freed, refId:0x5, pointer:0x7f65a400d4a0 -1230:09/09 18:52:59.483622 00166866 C TSC 0x6 free Request from connObj: 0x2, reqId:0x987bae6a58a90008 elapsed:49.78 ms, current:0, app current:0 -1234:09/09 18:52:59.483739 00166862 C RPC TSC conn 0x7f65bc000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:17, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a5800021 -1236:09/09 18:52:59.483813 00166860 C RPC TSC conn 0x7f65d4000c40 receive release req, qid:18, gtid:0x987bae6a58a90008:0x31de1d66a580001e -1242:09/09 18:52:59.483854 00166862 C RPC TSC conn 0x7f65bc000c40 drop-task is sent to 127.0.0.1:6100, local info:127.0.0.1:57880, seq:18, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a5800022 -1246:09/09 18:52:59.484011 00166862 C RPC TSC conn 0x7f65bc000c40 receive release req, qid:17, gtid:0x987bae6a58a90008:0x31de1d66a580001d -1250:09/09 18:52:59.484124 00166862 C RPC TSC conn 0x7f65bc000c40 receive release req, qid:19, gtid:0x987bae6a58a90008:0x31de1d66a580001f From 7af79f1bba55955a8423a4b5ac825f9563030d3c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 21 Oct 2024 17:09:25 +0800 Subject: [PATCH 237/240] Merge remote-tracking branch 'origin/3.0' into enh/opt-transport --- source/libs/transport/src/transCli.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3047843270..12e39cdd6e 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3491,6 +3491,12 @@ int32_t transSetDefaultAddr(void* pInstRef, const char* ip, const char* fqdn) { } pCtx->pCvtAddr = (SCvtAddr*)taosMemoryCalloc(1, sizeof(SCvtAddr)); + if (pCtx->pCvtAddr == NULL) { + taosMemoryFree(pCtx); + code = terrno; + break; + } + memcpy(pCtx->pCvtAddr, &cvtAddr, sizeof(SCvtAddr)); SCliReq* pReq = taosMemoryCalloc(1, sizeof(SCliReq)); From 8eefec09163a25143ec94fde07af229d8c54c05e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 21 Oct 2024 17:16:56 +0800 Subject: [PATCH 238/240] update parameter --- source/common/src/tglobal.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index fbc804bc6e..7d8a4c5b31 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -57,7 +57,7 @@ int32_t tsShellActivityTimer = 3; // second int32_t tsNumOfRpcThreads = 1; int32_t tsNumOfRpcSessions = 30000; int32_t tsShareConnLimit = 8; -int32_t tsReadTimeout = 128; +int32_t tsReadTimeout = 900; int32_t tsTimeToGetAvailableConn = 500000; int32_t tsKeepAliveIdle = 60; @@ -362,7 +362,7 @@ static int32_t taosSplitS3Cfg(SConfig *pCfg, const char *name, char gVarible[TSD TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, name); char *strDup = NULL; - if ((strDup = taosStrdup(pItem->str))== NULL){ + if ((strDup = taosStrdup(pItem->str)) == NULL) { code = terrno; goto _exit; } @@ -618,8 +618,8 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 256); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "shareConnLimit", tsShareConnLimit, 1, 256, CFG_SCOPE_BOTH, CFG_DYN_NONE)); - tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "readTimeout", tsReadTimeout, 64, 24 * 3600, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600 * 7); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "readTimeout", tsReadTimeout, 64, 24 * 3600 * 7, CFG_SCOPE_BOTH, CFG_DYN_NONE)); tsTimeToGetAvailableConn = TRANGE(tsTimeToGetAvailableConn, 20, 10000000); TAOS_CHECK_RETURN( @@ -897,7 +897,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem = cfgGetItem(pCfg, "readTimeout"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600); + tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600 * 7); pItem->i32 = tsReadTimeout; pItem->stype = stype; } @@ -1760,7 +1760,7 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char * TAOS_CHECK_GOTO(cfgAddDir(pCfg, "dataDir", tsDataDir, CFG_SCOPE_SERVER, CFG_DYN_NONE), NULL, _exit); TAOS_CHECK_GOTO(cfgAddInt32(pCfg, "debugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER), NULL, _exit); - TAOS_CHECK_GOTO(cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) ,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) { (void)printf("failed to load cfg since %s\n", tstrerror(code)); From 0d57d0f5639406445d39a70d185b3d0fa06279ab Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 21 Oct 2024 17:19:35 +0800 Subject: [PATCH 239/240] update parameter --- source/common/src/tglobal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 7d8a4c5b31..7cff5de008 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -615,8 +615,8 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { tsNumOfRpcSessions = TRANGE(tsNumOfRpcSessions, 100, 100000); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfRpcSessions", tsNumOfRpcSessions, 1, 100000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); - tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 256); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "shareConnLimit", tsShareConnLimit, 1, 256, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 512); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "shareConnLimit", tsShareConnLimit, 1, 512, CFG_SCOPE_BOTH, CFG_DYN_NONE)); tsReadTimeout = TRANGE(tsReadTimeout, 64, 24 * 3600 * 7); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "readTimeout", tsReadTimeout, 64, 24 * 3600 * 7, CFG_SCOPE_BOTH, CFG_DYN_NONE)); @@ -890,7 +890,7 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem = cfgGetItem(pCfg, "shareConnLimit"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 256); + tsShareConnLimit = TRANGE(tsShareConnLimit, 1, 512); pItem->i32 = tsShareConnLimit; pItem->stype = stype; } From 3483fc6902f007cea4a82bb33961f8d9c2563688 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 21 Oct 2024 19:15:48 +0800 Subject: [PATCH 240/240] update batch limit --- source/libs/transport/src/transCli.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 12e39cdd6e..18bedab5c7 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1396,7 +1396,8 @@ int32_t cliBatchSend(SCliConn* pConn, int8_t direct) { wb = pConn->buf; - int j = 0; + int j = 0; + int32_t batchLimit = 64; while (!transQueueEmpty(&pConn->reqsToSend)) { queue* h = transQueuePop(&pConn->reqsToSend); SCliReq* pCliMsg = QUEUE_DATA(h, SCliReq, q); @@ -1453,6 +1454,9 @@ int32_t cliBatchSend(SCliConn* pConn, int8_t direct) { tGDebug("%s conn %p %s is sent to %s, local info:%s, seq:%" PRId64 ", sid:%" PRId64 "", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pReq->msgType), pConn->dst, pConn->src, pConn->seq, pReq->info.qId); transQueuePush(&pConn->reqsSentOut, &pCliMsg->q); + if (j >= batchLimit) { + break; + } } transRefCliHandle(pConn); uv_write_t* req = allocWReqFromWQ(&pConn->wq, pConn); @@ -1462,7 +1466,7 @@ int32_t cliBatchSend(SCliConn* pConn, int8_t direct) { return terrno; } - tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, size, totalLen); + tDebug("%s conn %p start to send msg, batch size:%d, len:%d", CONN_GET_INST_LABEL(pConn), pConn, j, totalLen); int32_t ret = uv_write(req, (uv_stream_t*)pConn->stream, wb, j, cliBatchSendCb); if (ret != 0) {