refactor: rpc msg handler
This commit is contained in:
parent
d5fabd5375
commit
5ae72c15d4
|
@ -19,70 +19,43 @@
|
||||||
static inline void qmSendRsp(SRpcMsg *pMsg, int32_t code) {
|
static inline void qmSendRsp(SRpcMsg *pMsg, int32_t code) {
|
||||||
SRpcMsg rsp = {
|
SRpcMsg rsp = {
|
||||||
.code = code,
|
.code = code,
|
||||||
.info = pMsg->info,
|
|
||||||
.pCont = pMsg->info.rsp,
|
.pCont = pMsg->info.rsp,
|
||||||
.contLen = pMsg->info.rspLen,
|
.contLen = pMsg->info.rspLen,
|
||||||
|
.info = pMsg->info,
|
||||||
};
|
};
|
||||||
tmsgSendRsp(&rsp);
|
tmsgSendRsp(&rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qmProcessMonitorQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
static void qmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
SQnodeMgmt *pMgmt = pInfo->ahandle;
|
SQnodeMgmt *pMgmt = pInfo->ahandle;
|
||||||
|
int32_t code = -1;
|
||||||
|
dTrace("msg:%p, get from qnode queue", pMsg);
|
||||||
|
|
||||||
dTrace("msg:%p, get from qnode-monitor queue", pMsg);
|
switch (pMsg->msgType) {
|
||||||
SRpcMsg *pRpc = pMsg;
|
case TDMT_MON_QM_INFO:
|
||||||
int32_t code = -1;
|
code = qmProcessGetMonitorInfoReq(pMgmt, pMsg);
|
||||||
|
break;
|
||||||
if (pMsg->msgType == TDMT_MON_QM_INFO) {
|
case TDMT_VND_QUERY:
|
||||||
code = qmProcessGetMonitorInfoReq(pMgmt, pMsg);
|
case TDMT_VND_QUERY_CONTINUE:
|
||||||
} else {
|
code = qndProcessQueryMsg(pMgmt->pQnode, pMsg);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
break;
|
||||||
|
default:
|
||||||
|
code = qndProcessFetchMsg(pMgmt->pQnode, pMsg);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRpc->msgType & 1U) {
|
if (IsReq(pMsg) && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||||
if (code != 0 && terrno != 0) code = terrno;
|
if (code != 0 && terrno != 0) code = terrno;
|
||||||
qmSendRsp(pMsg, code);
|
qmSendRsp(pMsg, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
|
||||||
rpcFreeCont(pRpc->pCont);
|
|
||||||
taosFreeQitem(pMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|
||||||
SQnodeMgmt *pMgmt = pInfo->ahandle;
|
|
||||||
|
|
||||||
dTrace("msg:%p, get from qnode-query queue", pMsg);
|
|
||||||
SRpcMsg *pRpc = pMsg;
|
|
||||||
int32_t code = qndProcessQueryMsg(pMgmt->pQnode, pRpc);
|
|
||||||
|
|
||||||
if (pRpc->msgType & 1U && code != 0) {
|
|
||||||
qmSendRsp(pMsg, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
|
||||||
rpcFreeCont(pMsg->pCont);
|
|
||||||
taosFreeQitem(pMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|
||||||
SQnodeMgmt *pMgmt = pInfo->ahandle;
|
|
||||||
|
|
||||||
dTrace("msg:%p, get from qnode-fetch queue", pMsg);
|
|
||||||
SRpcMsg *pRpc = pMsg;
|
|
||||||
int32_t code = qndProcessFetchMsg(pMgmt->pQnode, pRpc);
|
|
||||||
|
|
||||||
if (pRpc->msgType & 1U && code != 0) {
|
|
||||||
qmSendRsp(pMsg, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t qmPutNodeMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pMsg) {
|
static int32_t qmPutNodeMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pMsg) {
|
||||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
dTrace("msg:%p, put into worker %s, type:%s", pMsg, pWorker->name, TMSG_INFO(pMsg->msgType));
|
||||||
taosWriteQitem(pWorker->queue, pMsg);
|
taosWriteQitem(pWorker->queue, pMsg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -101,9 +74,7 @@ int32_t qmPutNodeMsgToMonitorQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
|
||||||
static int32_t qmPutRpcMsgToWorker(SQnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) {
|
static int32_t qmPutRpcMsgToWorker(SQnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) {
|
||||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM);
|
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM);
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) return -1;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dTrace("msg:%p, create and put into worker:%s, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType));
|
dTrace("msg:%p, create and put into worker:%s, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType));
|
||||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||||
|
@ -141,7 +112,7 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
.min = tsNumOfVnodeQueryThreads,
|
.min = tsNumOfVnodeQueryThreads,
|
||||||
.max = tsNumOfVnodeQueryThreads,
|
.max = tsNumOfVnodeQueryThreads,
|
||||||
.name = "qnode-query",
|
.name = "qnode-query",
|
||||||
.fp = (FItem)qmProcessQueryQueue,
|
.fp = (FItem)qmProcessQueue,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -154,7 +125,7 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
.min = tsNumOfQnodeFetchThreads,
|
.min = tsNumOfQnodeFetchThreads,
|
||||||
.max = tsNumOfQnodeFetchThreads,
|
.max = tsNumOfQnodeFetchThreads,
|
||||||
.name = "qnode-fetch",
|
.name = "qnode-fetch",
|
||||||
.fp = (FItem)qmProcessFetchQueue,
|
.fp = (FItem)qmProcessQueue,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -167,7 +138,7 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
.min = 1,
|
.min = 1,
|
||||||
.max = 1,
|
.max = 1,
|
||||||
.name = "qnode-monitor",
|
.name = "qnode-monitor",
|
||||||
.fp = (FItem)qmProcessMonitorQueue,
|
.fp = (FItem)qmProcessQueue,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) {
|
if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) {
|
||||||
|
|
|
@ -43,44 +43,63 @@ void qndClose(SQnode *pQnode) {
|
||||||
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }
|
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }
|
||||||
|
|
||||||
int32_t qndProcessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
int32_t qndProcessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
||||||
qTrace("message in qnode query queue is processing");
|
int32_t code = -1;
|
||||||
SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
|
SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
|
||||||
|
qTrace("message in qnode query queue is processing");
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
case TDMT_VND_QUERY: {
|
case TDMT_VND_QUERY:
|
||||||
return qWorkerProcessQueryMsg(&handle, pQnode->pQuery, pMsg);
|
code = qWorkerProcessQueryMsg(&handle, pQnode->pQuery, pMsg);
|
||||||
}
|
break;
|
||||||
case TDMT_VND_QUERY_CONTINUE:
|
case TDMT_VND_QUERY_CONTINUE:
|
||||||
return qWorkerProcessCQueryMsg(&handle, pQnode->pQuery, pMsg);
|
code = qWorkerProcessCQueryMsg(&handle, pQnode->pQuery, pMsg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qError("unknown msg type:%d in query queue", pMsg->msgType);
|
qError("unknown msg type:%d in query queue", pMsg->msgType);
|
||||||
return TSDB_CODE_VND_APP_ERROR;
|
terrno = TSDB_CODE_VND_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qndProcessFetchMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
int32_t qndProcessFetchMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = -1;
|
||||||
qTrace("message in fetch queue is processing");
|
qTrace("message in fetch queue is processing");
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
case TDMT_VND_FETCH:
|
case TDMT_VND_FETCH:
|
||||||
return qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg);
|
code = qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg);
|
||||||
|
break;
|
||||||
case TDMT_VND_FETCH_RSP:
|
case TDMT_VND_FETCH_RSP:
|
||||||
return qWorkerProcessFetchRsp(pQnode, pQnode->pQuery, pMsg);
|
code = qWorkerProcessFetchRsp(pQnode, pQnode->pQuery, pMsg);
|
||||||
|
break;
|
||||||
case TDMT_VND_RES_READY:
|
case TDMT_VND_RES_READY:
|
||||||
return qWorkerProcessReadyMsg(pQnode, pQnode->pQuery, pMsg);
|
code = qWorkerProcessReadyMsg(pQnode, pQnode->pQuery, pMsg);
|
||||||
|
break;
|
||||||
case TDMT_VND_TASKS_STATUS:
|
case TDMT_VND_TASKS_STATUS:
|
||||||
return qWorkerProcessStatusMsg(pQnode, pQnode->pQuery, pMsg);
|
code = qWorkerProcessStatusMsg(pQnode, pQnode->pQuery, pMsg);
|
||||||
|
break;
|
||||||
case TDMT_VND_CANCEL_TASK:
|
case TDMT_VND_CANCEL_TASK:
|
||||||
return qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg);
|
code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg);
|
||||||
|
break;
|
||||||
case TDMT_VND_DROP_TASK:
|
case TDMT_VND_DROP_TASK:
|
||||||
return qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg);
|
code = qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg);
|
||||||
|
break;
|
||||||
case TDMT_VND_TABLE_META:
|
case TDMT_VND_TABLE_META:
|
||||||
// return vnodeGetTableMeta(pQnode, pMsg);
|
// code = vnodeGetTableMeta(pQnode, pMsg);
|
||||||
|
// break;
|
||||||
case TDMT_VND_CONSUME:
|
case TDMT_VND_CONSUME:
|
||||||
// return tqProcessConsumeReq(pQnode->pTq, pMsg);
|
// code = tqProcessConsumeReq(pQnode->pTq, pMsg);
|
||||||
|
// break;
|
||||||
case TDMT_VND_QUERY_HEARTBEAT:
|
case TDMT_VND_QUERY_HEARTBEAT:
|
||||||
return qWorkerProcessHbMsg(pQnode, pQnode->pQuery, pMsg);
|
code = qWorkerProcessHbMsg(pQnode, pQnode->pQuery, pMsg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
qError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
||||||
return TSDB_CODE_VND_APP_ERROR;
|
terrno = TSDB_CODE_VND_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue