refactor transport

This commit is contained in:
Yihao Deng 2024-05-07 03:10:35 +00:00
parent 02ff9967fb
commit 8c11a7e998
1 changed files with 77 additions and 79 deletions

View File

@ -212,8 +212,10 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd);
static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd); static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd);
static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL, static void (*cliAsyncHandle[])(SCliMsg* pMsg, SCliThrd* pThrd) = {cliHandleReq, cliHandleQuit, cliHandleRelease, NULL,
cliHandleUpdate}; 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); 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); 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; int count = 0;
while (!QUEUE_IS_EMPTY(wq)) { while (!QUEUE_IS_EMPTY(wq)) {
@ -1709,7 +1711,6 @@ static void cliNoBatchDealReq(queue* wq, SCliThrd* pThrd) {
continue; continue;
} }
(*cliAsyncHandle[pMsg->type])(pMsg, pThrd); (*cliAsyncHandle[pMsg->type])(pMsg, pThrd);
count++; count++;
} }
if (count >= 2) { if (count >= 2) {
@ -1729,23 +1730,8 @@ SCliBatch* cliGetHeadFromList(SCliBatchList* pList) {
SCliBatch* batch = QUEUE_DATA(hr, SCliBatch, listq); SCliBatch* batch = QUEUE_DATA(hr, SCliBatch, listq);
return batch; return batch;
} }
static void cliBuildBatch(SCliMsg* pMsg, queue* h, SCliThrd* pThrd) {
static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) {
STrans* pInst = pThrd->pTransInst; STrans* pInst = pThrd->pTransInst;
int count = 0;
while (!QUEUE_IS_EMPTY(wq)) {
queue* h = QUEUE_HEAD(wq);
QUEUE_REMOVE(h);
SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q);
if (pMsg->type == Quit) {
pThrd->stopMsg = pMsg;
continue;
}
if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) {
STransConnCtx* pCtx = pMsg->ctx; STransConnCtx* pCtx = pMsg->ctx;
char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet); char* ip = EPSET_GET_INUSE_IP(&pCtx->epSet);
@ -1791,8 +1777,6 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) {
QUEUE_PUSH(&((*ppBatchList)->wq), &pBatch->listq); QUEUE_PUSH(&((*ppBatchList)->wq), &pBatch->listq);
(*ppBatchList)->len += 1; (*ppBatchList)->len += 1;
continue;
} }
queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq)); queue* hdr = QUEUE_TAIL(&((*ppBatchList)->wq));
@ -1815,6 +1799,25 @@ static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) {
(*ppBatchList)->len += 1; (*ppBatchList)->len += 1;
} }
} }
return;
}
static void cliBatchDealReq(queue* wq, SCliThrd* pThrd) {
STrans* pInst = pThrd->pTransInst;
int count = 0;
while (!QUEUE_IS_EMPTY(wq)) {
queue* h = QUEUE_HEAD(wq);
QUEUE_REMOVE(h);
SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q);
if (pMsg->type == Quit) {
pThrd->stopMsg = pMsg;
continue;
}
if (pMsg->type == Normal && REQUEST_NO_RESP(&pMsg->msg)) {
cliBuildBatch(pMsg, h, pThrd);
continue; continue;
} }
(*cliAsyncHandle[pMsg->type])(pMsg, pThrd); (*cliAsyncHandle[pMsg->type])(pMsg, pThrd);
@ -1847,12 +1850,7 @@ static void cliAsyncCb(uv_async_t* handle) {
QUEUE_MOVE(&item->qmsg, &wq); QUEUE_MOVE(&item->qmsg, &wq);
taosThreadMutexUnlock(&item->mtx); taosThreadMutexUnlock(&item->mtx);
int8_t supportBatch = pTransInst->supportBatch; cliDealFunc[pTransInst->supportBatch](&wq, pThrd);
if (supportBatch == 0) {
cliNoBatchDealReq(&wq, pThrd);
} else if (supportBatch == 1) {
cliBatchDealReq(&wq, pThrd);
}
if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd); if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd);
} }