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
|
|
|
*/
|
|
|
|
|
|
2024-07-24 06:41:45 +00:00
|
|
|
#include "tqueue.h"
|
|
|
|
|
|
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"
|
2021-12-27 10:43:27 +00:00
|
|
|
|
2024-07-22 02:58:55 +00:00
|
|
|
int32_t qndOpen(const SQnodeOpt *pOption, SQnode **pQnode) {
|
|
|
|
|
*pQnode = taosMemoryCalloc(1, sizeof(SQnode));
|
|
|
|
|
if (NULL == *pQnode) {
|
2022-03-07 11:37:17 +00:00
|
|
|
qError("calloc SQnode failed");
|
2024-07-24 05:58:17 +00:00
|
|
|
return terrno;
|
2022-03-07 11:37:17 +00:00
|
|
|
}
|
2024-07-22 02:58:55 +00:00
|
|
|
(*pQnode)->qndId = QNODE_HANDLE;
|
2022-03-07 11:37:17 +00:00
|
|
|
|
2024-07-22 02:58:55 +00:00
|
|
|
int32_t code = qWorkerInit(NODE_TYPE_QNODE, (*pQnode)->qndId, (void **)&(*pQnode)->pQuery, &pOption->msgCb);
|
|
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
2022-03-25 16:29:53 +00:00
|
|
|
taosMemoryFreeClear(pQnode);
|
2024-07-22 02:58:55 +00:00
|
|
|
return code;
|
2022-03-07 11:37:17 +00:00
|
|
|
}
|
2022-03-21 11:08:25 +00:00
|
|
|
|
2024-07-22 02:58:55 +00:00
|
|
|
(*pQnode)->msgCb = pOption->msgCb;
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
2021-12-27 10:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
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-10-13 03:56:16 +00:00
|
|
|
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) {
|
|
|
|
|
SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
|
2022-05-31 06:03:47 +00:00
|
|
|
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;
|
2023-08-25 06:59:34 +00:00
|
|
|
pLoad->numOfProcessedNotify = stat.notifyProcessed;
|
2022-05-31 06:03:47 +00:00
|
|
|
pLoad->numOfProcessedHb = stat.hbProcessed;
|
2022-06-05 12:33:21 +00:00
|
|
|
pLoad->numOfProcessedDelete = stat.deleteProcessed;
|
2022-10-13 03:56:16 +00:00
|
|
|
|
|
|
|
|
return 0;
|
2022-05-28 14:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-13 03:56:16 +00:00
|
|
|
int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
2025-09-29 02:01:33 +00:00
|
|
|
int32_t qType = 0;
|
2022-06-29 02:51:22 +00:00
|
|
|
if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
|
2022-06-04 01:57:16 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-29 02:01:33 +00:00
|
|
|
return qWorkerPreprocessQueryMsg(pQnode->pQuery, pMsg, false, &qType);
|
2022-06-04 01:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-24 05:58:17 +00:00
|
|
|
int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
2022-05-21 09:47:29 +00:00
|
|
|
int32_t code = -1;
|
2024-07-24 05:58:17 +00:00
|
|
|
int64_t ts = pInfo->timestamp;
|
2025-07-16 06:42:16 +00:00
|
|
|
SReadHandle handle = {0};
|
|
|
|
|
handle.pMsgCb = &pQnode->msgCb;
|
|
|
|
|
handle.pWorkerCb = pInfo->workerCb;
|
2026-01-22 05:39:05 +00:00
|
|
|
|
|
|
|
|
const STraceId *trace = &pMsg->info.traceId;
|
|
|
|
|
qDebug("qnodeId:%d, msg:%s, %p in qnode queue is processing, %" PRIx64 ":%" PRIx64,
|
|
|
|
|
pQnode->qndId, TMSG_INFO(pMsg->msgType), pMsg, TRACE_GET_ROOTID(trace), TRACE_GET_MSGID(trace));
|
2022-03-07 11:37:17 +00:00
|
|
|
|
|
|
|
|
switch (pMsg->msgType) {
|
2022-06-28 02:34:51 +00:00
|
|
|
case TDMT_SCH_QUERY:
|
2022-06-29 02:51:22 +00:00
|
|
|
case TDMT_SCH_MERGE_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-06-28 02:34:51 +00:00
|
|
|
case TDMT_SCH_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-06-28 02:34:51 +00:00
|
|
|
case TDMT_SCH_FETCH:
|
2022-07-06 12:33:23 +00:00
|
|
|
case TDMT_SCH_MERGE_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-06-28 02:34:51 +00:00
|
|
|
case TDMT_SCH_CANCEL_TASK:
|
2022-10-31 10:37:28 +00:00
|
|
|
// code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg, ts);
|
2022-05-21 09:47:29 +00:00
|
|
|
break;
|
2022-06-28 02:34:51 +00:00
|
|
|
case TDMT_SCH_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-10-31 10:37:28 +00:00
|
|
|
case TDMT_VND_TMQ_CONSUME:
|
2022-05-21 09:47:29 +00:00
|
|
|
// code = tqProcessConsumeReq(pQnode->pTq, pMsg);
|
|
|
|
|
// break;
|
2022-06-28 02:34:51 +00:00
|
|
|
case TDMT_SCH_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;
|
2023-08-25 06:59:34 +00:00
|
|
|
case TDMT_SCH_TASK_NOTIFY:
|
|
|
|
|
code = qWorkerProcessNotifyMsg(pQnode, pQnode->pQuery, pMsg, ts);
|
|
|
|
|
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-11-02 07:28:32 +00:00
|
|
|
terrno = TSDB_CODE_APP_ERROR;
|
2022-03-07 11:37:17 +00:00
|
|
|
}
|
2022-05-21 09:47:29 +00:00
|
|
|
|
2024-07-24 05:58:17 +00:00
|
|
|
if (code == 0) {
|
|
|
|
|
return TSDB_CODE_ACTION_IN_PROGRESS;
|
|
|
|
|
} else {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2022-03-07 11:37:17 +00:00
|
|
|
}
|