refactor tranport

This commit is contained in:
Yihao Deng 2024-05-23 06:49:24 +00:00
parent 81a4ef73f1
commit a0abe67432
2 changed files with 57 additions and 49 deletions

View File

@ -69,6 +69,7 @@ typedef struct {
int8_t connLimitLock; // 0: no lock. 1. lock int8_t connLimitLock; // 0: no lock. 1. lock
int8_t supportBatch; // 0: no batch, 1: support batch int8_t supportBatch; // 0: no batch, 1: support batch
int32_t batchSize; int32_t batchSize;
int8_t optBatchFetch;
int32_t timeToGetConn; int32_t timeToGetConn;
int index; int index;
void* parent; void* parent;

View File

@ -1213,47 +1213,22 @@ static void cliDestroyBatch(SCliBatch* pBatch) {
p->sending -= 1; p->sending -= 1;
taosMemoryFree(pBatch); taosMemoryFree(pBatch);
} }
static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) {
if (pThrd->quit == true) {
cliDestroyBatch(pBatch);
return;
}
if (pBatch == NULL || pBatch->wLen == 0 || QUEUE_IS_EMPTY(&pBatch->wq)) { static void cliDoConn(SCliThrd* pThrd, SCliConn* conn, char* ip, int port) {
return;
}
STrans* pTransInst = pThrd->pTransInst; STrans* pTransInst = pThrd->pTransInst;
SCliBatchList* pList = pBatch->pList; uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, ip);
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);
if (conn == NULL && exceed) {
tError("%s failed to send batch msg, batch size:%d, msgLen: %d, conn limit:%d", pTransInst->label, pBatch->wLen,
pBatch->batchSize, pTransInst->connLimitNum);
cliDestroyBatch(pBatch);
return;
}
if (conn == NULL) {
conn = cliCreateConn(pThrd);
conn->pBatch = pBatch;
conn->dstAddr = taosStrdup(pList->dst);
uint32_t ipaddr = cliGetIpFromFqdnCache(pThrd->fqdn2ipCache, pList->ip);
if (ipaddr == 0xffffffff) { if (ipaddr == 0xffffffff) {
cliResetConnTimer(conn); cliResetConnTimer(conn);
cliHandleFastFail(conn, -1); cliHandleFastFail(conn, -1);
return; return;
} }
struct sockaddr_in addr; struct sockaddr_in addr;
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_addr.s_addr = ipaddr; addr.sin_addr.s_addr = ipaddr;
addr.sin_port = (uint16_t)htons(pList->port); addr.sin_port = (uint16_t)htons(port);
tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, pList->dst); tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, conn->dstAddr);
int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10);
if (fd == -1) { if (fd == -1) {
tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn,
@ -1284,6 +1259,34 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) {
uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0);
return; 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;
}
STrans* pTransInst = pThrd->pTransInst;
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", pTransInst->label, pBatch->wLen,
pBatch->batchSize, pTransInst->connLimitNum);
cliDestroyBatch(pBatch);
return;
}
if (conn == NULL) {
conn = cliCreateConn(pThrd);
conn->pBatch = pBatch;
conn->dstAddr = taosStrdup(pList->dst);
return cliDoConn(pThrd, conn, pList->ip, pList->port);
}
conn->pBatch = pBatch; conn->pBatch = pBatch;
cliSendBatch(conn); cliSendBatch(conn);
@ -1803,6 +1806,10 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) {
SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); 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)) { if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) {
cliBuildBatch(pMsg, h, pThrd); cliBuildBatch(pMsg, h, pThrd);
continue; continue;