TDengine/source/dnode/mnode/impl/src/mndQuery.c

84 lines
3 KiB
C
Raw Normal View History

2022-03-25 05:27:14 +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/>.
*/
#include "mndQuery.h"
#include "executor.h"
2022-03-28 11:55:45 +00:00
#include "mndMnode.h"
2022-03-25 05:27:14 +00:00
#include "qworker.h"
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg) {
2022-06-29 02:51:22 +00:00
if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return 0;
2022-06-14 08:01:32 +00:00
SMnode *pMnode = pMsg->info.node;
2022-06-04 01:57:16 +00:00
return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg);
}
void mndPostProcessQueryMsg(SRpcMsg *pMsg) {
2022-06-29 02:51:22 +00:00
if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return;
2022-06-20 03:37:40 +00:00
SMnode *pMnode = pMsg->info.node;
qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg);
}
2022-05-21 09:57:39 +00:00
int32_t mndProcessQueryMsg(SRpcMsg *pMsg) {
2022-05-21 09:38:09 +00:00
int32_t code = -1;
2022-05-21 09:57:39 +00:00
SMnode *pMnode = pMsg->info.node;
SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb};
2022-03-25 05:27:14 +00:00
2022-05-21 09:57:39 +00:00
mTrace("msg:%p, in query queue is processing", pMsg);
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, pMnode->pQuery, pMsg, 0);
2022-05-21 09:38:09 +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, pMnode->pQuery, pMsg, 0);
2022-05-21 09:38:09 +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(pMnode, pMnode->pQuery, pMsg, 0);
2022-05-21 09:38:09 +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(pMnode, pMnode->pQuery, pMsg, 0);
2022-05-21 09:38:09 +00:00
break;
2022-06-28 02:34:51 +00:00
case TDMT_SCH_QUERY_HEARTBEAT:
2022-05-28 14:13:26 +00:00
code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg, 0);
2022-05-21 09:38:09 +00:00
break;
2022-03-25 05:27:14 +00:00
default:
2022-05-21 09:38:09 +00:00
terrno = TSDB_CODE_VND_APP_ERROR;
2022-05-21 09:57:39 +00:00
mError("unknown msg type:%d in query queue", pMsg->msgType);
2022-03-25 05:27:14 +00:00
}
2022-05-21 09:38:09 +00:00
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
return code;
2022-03-25 05:27:14 +00:00
}
int32_t mndInitQuery(SMnode *pMnode) {
2022-04-02 11:52:04 +00:00
if (qWorkerInit(NODE_TYPE_MNODE, MNODE_HANDLE, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb) != 0) {
2022-03-28 11:55:45 +00:00
mError("failed to init qworker in mnode since %s", terrstr());
return -1;
2022-03-25 05:27:14 +00:00
}
2022-06-28 02:34:51 +00:00
mndSetMsgHandle(pMnode, TDMT_SCH_QUERY, mndProcessQueryMsg);
2022-06-29 02:51:22 +00:00
mndSetMsgHandle(pMnode, TDMT_SCH_MERGE_QUERY, mndProcessQueryMsg);
2022-06-28 02:34:51 +00:00
mndSetMsgHandle(pMnode, TDMT_SCH_QUERY_CONTINUE, mndProcessQueryMsg);
mndSetMsgHandle(pMnode, TDMT_SCH_FETCH, mndProcessQueryMsg);
2022-07-06 12:33:23 +00:00
mndSetMsgHandle(pMnode, TDMT_SCH_MERGE_FETCH, mndProcessQueryMsg);
2022-06-28 02:34:51 +00:00
mndSetMsgHandle(pMnode, TDMT_SCH_DROP_TASK, mndProcessQueryMsg);
mndSetMsgHandle(pMnode, TDMT_SCH_QUERY_HEARTBEAT, mndProcessQueryMsg);
2022-03-25 05:27:14 +00:00
return 0;
}
void mndCleanupQuery(SMnode *pMnode) { qWorkerDestroy((void **)&pMnode->pQuery); }