TDengine/source/dnode/qnode/src/qnode.c

112 lines
3.4 KiB
C
Raw Normal View History

2021-09-22 08:29:27 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2021-12-27 10:43:27 +00:00
*/
2022-03-21 11:08:25 +00:00
#include "executor.h"
2021-12-27 10:43:27 +00:00
#include "qndInt.h"
2022-03-09 08:13:46 +00:00
#include "query.h"
#include "qworker.h"
2022-04-26 08:57:08 +00:00
#include "libs/function/function.h"
2021-12-27 10:43:27 +00:00
SQnode *qndOpen(const SQnodeOpt *pOption) {
2022-03-25 16:29:53 +00:00
SQnode *pQnode = taosMemoryCalloc(1, sizeof(SQnode));
2022-03-07 11:37:17 +00:00
if (NULL == pQnode) {
qError("calloc SQnode failed");
return NULL;
}
2022-03-21 11:08:25 +00:00
if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, NULL, (void **)&pQnode->pQuery, &pOption->msgCb)) {
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(pQnode);
2022-03-07 11:37:17 +00:00
return NULL;
}
2022-03-21 11:08:25 +00:00
pQnode->msgCb = pOption->msgCb;
2021-12-27 10:43:27 +00:00
return pQnode;
}
2022-03-21 11:49:20 +00:00
void qndClose(SQnode *pQnode) {
2022-03-09 08:13:46 +00:00
qWorkerDestroy((void **)&pQnode->pQuery);
2022-03-25 16:29:53 +00:00
taosMemoryFree(pQnode);
2022-03-07 11:37:17 +00:00
}
2021-12-27 10:43:27 +00:00
2022-05-28 14:13:26 +00:00
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) {
2022-05-31 06:03:47 +00:00
SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
SQWorkerStat stat = {0};
int32_t code = qWorkerGetStat(&handle, pQnode->pQuery, &stat);
if (code) {
return code;
}
2021-12-27 10:43:27 +00:00
2022-05-31 06:03:47 +00:00
pLoad->numOfQueryInQueue = stat.numOfQueryInQueue;
pLoad->numOfFetchInQueue = stat.numOfFetchInQueue;
pLoad->timeInQueryQueue = stat.timeInQueryQueue;
pLoad->timeInFetchQueue = stat.timeInFetchQueue;
pLoad->cacheDataSize = stat.cacheDataSize;
pLoad->numOfProcessedQuery = stat.queryProcessed;
pLoad->numOfProcessedCQuery = stat.cqueryProcessed;
pLoad->numOfProcessedFetch = stat.fetchProcessed;
pLoad->numOfProcessedDrop = stat.dropProcessed;
pLoad->numOfProcessedHb = stat.hbProcessed;
2022-05-28 14:13:26 +00:00
return 0;
}
2022-06-04 01:57:16 +00:00
int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg * pMsg) {
if (TDMT_VND_QUERY != pMsg->msgType) {
return 0;
}
return qWorkerPreprocessQueryMsg(pQnode->pQuery, pMsg);
}
2022-05-28 14:13:26 +00:00
int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg) {
2022-05-21 09:47:29 +00:00
int32_t code = -1;
SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
2022-05-21 09:57:39 +00:00
qTrace("message in qnode queue is processing");
2022-03-07 11:37:17 +00:00
switch (pMsg->msgType) {
2022-05-21 09:47:29 +00:00
case TDMT_VND_QUERY:
2022-05-28 14:13:26 +00:00
code = qWorkerProcessQueryMsg(&handle, pQnode->pQuery, pMsg, ts);
2022-05-21 09:47:29 +00:00
break;
2022-03-07 11:37:17 +00:00
case TDMT_VND_QUERY_CONTINUE:
2022-05-28 14:13:26 +00:00
code = qWorkerProcessCQueryMsg(&handle, pQnode->pQuery, pMsg, ts);
2022-05-21 09:47:29 +00:00
break;
2022-03-07 11:37:17 +00:00
case TDMT_VND_FETCH:
2022-05-28 14:13:26 +00:00
code = qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg, ts);
2022-05-21 09:47:29 +00:00
break;
2022-03-07 11:37:17 +00:00
case TDMT_VND_FETCH_RSP:
2022-05-28 14:13:26 +00:00
code = qWorkerProcessFetchRsp(pQnode, pQnode->pQuery, pMsg, ts);
2022-05-21 09:47:29 +00:00
break;
2022-03-07 11:37:17 +00:00
case TDMT_VND_CANCEL_TASK:
2022-05-28 14:13:26 +00:00
code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg, ts);
2022-05-21 09:47:29 +00:00
break;
2022-03-07 11:37:17 +00:00
case TDMT_VND_DROP_TASK:
2022-05-28 14:13:26 +00:00
code = qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg, ts);
2022-05-21 09:47:29 +00:00
break;
2022-03-07 11:37:17 +00:00
case TDMT_VND_CONSUME:
2022-05-21 09:47:29 +00:00
// code = tqProcessConsumeReq(pQnode->pTq, pMsg);
// break;
2022-05-06 08:35:24 +00:00
case TDMT_VND_QUERY_HEARTBEAT:
2022-05-28 14:13:26 +00:00
code = qWorkerProcessHbMsg(pQnode, pQnode->pQuery, pMsg, ts);
2022-05-21 09:47:29 +00:00
break;
2022-03-07 11:37:17 +00:00
default:
2022-05-21 09:57:39 +00:00
qError("unknown msg type:%d in qnode queue", pMsg->msgType);
2022-05-21 09:47:29 +00:00
terrno = TSDB_CODE_VND_APP_ERROR;
2022-03-07 11:37:17 +00:00
}
2022-05-21 09:47:29 +00:00
if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS;
return code;
2022-03-07 11:37:17 +00:00
}