From 0293a09187b79c3a95afc88131c14416a8281cc6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 27 May 2022 16:48:38 +0800 Subject: [PATCH] enh: return NULL when epset not updated --- source/libs/transport/inc/transComm.h | 4 +++- source/libs/transport/src/transCli.c | 5 ++++- source/libs/transport/src/transComm.c | 13 ++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 5ba6c4029e..a8093f46a2 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -112,7 +112,8 @@ typedef struct SCvtAddr { } SCvtAddr; typedef struct { - SEpSet epSet; // ip list provided by app + 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 @@ -344,6 +345,7 @@ void transDQDestroy(SDelayQueue* queue); int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs); void transPrintEpSet(SEpSet* pEpSet); +bool transEpSetIsEqual(SEpSet* a, SEpSet* b); /* * init global func */ diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 3220e229a6..c62214b9c1 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -947,6 +947,9 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { SEpSet* pEpSet = &pCtx->epSet; transPrintEpSet(pEpSet); + if (pCtx->retryCount == 0) { + pCtx->origEpSet = pCtx->epSet; + } /* * upper layer handle retry if code equal TSDB_CODE_RPC_NETWORK_UNAVAIL */ @@ -999,7 +1002,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { pCtx->pRsp = NULL; } else { tTrace("%s cli conn %p handle resp", pTransInst->label, pConn); - if (pResp->code != 0) { + if (pResp->code != 0 || pCtx->retryCount == 0 || transEpSetIsEqual(&pCtx->epSet, &pCtx->origEpSet)) { pTransInst->cfp(pTransInst->parent, pResp, NULL); } else { pTransInst->cfp(pTransInst->parent, pResp, pEpSet); diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index be07fbd264..333ec44fe4 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -453,10 +453,21 @@ void transPrintEpSet(SEpSet* pEpSet) { tTrace("NULL epset"); return; } - tTrace("epset begin: inUse: %d", pEpSet->inUse); + tTrace("epset begin inUse: %d", pEpSet->inUse); for (int i = 0; i < pEpSet->numOfEps; i++) { tTrace("ip: %s, port: %d", pEpSet->eps[i].fqdn, pEpSet->eps[i].port); } tTrace("epset end"); } +bool transEpSetIsEqual(SEpSet* a, SEpSet* b) { + if (a->numOfEps != b->numOfEps || a->inUse != b->inUse) { + return false; + } + for (int i = 0; i < a->numOfEps; i++) { + if (strncmp(a->eps[i].fqdn, b->eps[i].fqdn, TSDB_FQDN_LEN) != 0 || a->eps[i].port != b->eps[i].port) { + return false; + } + } + return true; +} #endif -- GitLab