mndQuery.c 3.0 KB
Newer Older
D
dapan1121 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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"
S
Shengliang Guan 已提交
18
#include "mndMnode.h"
D
dapan1121 已提交
19 20
#include "qworker.h"

21
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg) {
D
dapan1121 已提交
22
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return 0;
23
  SMnode *pMnode = pMsg->info.node;
D
dapan1121 已提交
24 25 26
  return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg);
}

27
void mndPostProcessQueryMsg(SRpcMsg *pMsg) {
D
dapan1121 已提交
28
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return;
D
dapan1121 已提交
29 30 31 32
  SMnode *pMnode = pMsg->info.node;
  qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg);
}

S
Shengliang Guan 已提交
33
int32_t mndProcessQueryMsg(SRpcMsg *pMsg) {
S
Shengliang Guan 已提交
34
  int32_t     code = -1;
S
Shengliang Guan 已提交
35
  SMnode     *pMnode = pMsg->info.node;
36
  SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb};
D
dapan1121 已提交
37

S
Shengliang Guan 已提交
38 39
  mTrace("msg:%p, in query queue is processing", pMsg);
  switch (pMsg->msgType) {
D
dapan1121 已提交
40
    case TDMT_SCH_QUERY:
D
dapan1121 已提交
41
    case TDMT_SCH_MERGE_QUERY:
D
dapan1121 已提交
42
      code = qWorkerProcessQueryMsg(&handle, pMnode->pQuery, pMsg, 0);
S
Shengliang Guan 已提交
43
      break;
D
dapan1121 已提交
44
    case TDMT_SCH_QUERY_CONTINUE:
D
dapan1121 已提交
45
      code = qWorkerProcessCQueryMsg(&handle, pMnode->pQuery, pMsg, 0);
S
Shengliang Guan 已提交
46
      break;
D
dapan1121 已提交
47
    case TDMT_SCH_FETCH:
D
dapan1121 已提交
48
    case TDMT_SCH_MERGE_FETCH:
D
dapan1121 已提交
49
      code = qWorkerProcessFetchMsg(pMnode, pMnode->pQuery, pMsg, 0);
S
Shengliang Guan 已提交
50
      break;
D
dapan1121 已提交
51
    case TDMT_SCH_DROP_TASK:
D
dapan1121 已提交
52
      code = qWorkerProcessDropMsg(pMnode, pMnode->pQuery, pMsg, 0);
S
Shengliang Guan 已提交
53
      break;
D
dapan1121 已提交
54
    case TDMT_SCH_QUERY_HEARTBEAT:
D
dapan1121 已提交
55
      code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg, 0);
S
Shengliang Guan 已提交
56
      break;
D
dapan1121 已提交
57
    default:
S
Shengliang Guan 已提交
58
      terrno = TSDB_CODE_VND_APP_ERROR;
S
Shengliang Guan 已提交
59
      mError("unknown msg type:%d in query queue", pMsg->msgType);
D
dapan1121 已提交
60
  }
S
Shengliang Guan 已提交
61 62 63

  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
  return code;
D
dapan1121 已提交
64 65 66
}

int32_t mndInitQuery(SMnode *pMnode) {
S
Shengliang Guan 已提交
67
  if (qWorkerInit(NODE_TYPE_MNODE, MNODE_HANDLE, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb) != 0) {
S
Shengliang Guan 已提交
68 69
    mError("failed to init qworker in mnode since %s", terrstr());
    return -1;
D
dapan1121 已提交
70 71
  }

D
dapan1121 已提交
72
  mndSetMsgHandle(pMnode, TDMT_SCH_QUERY, mndProcessQueryMsg);
D
dapan1121 已提交
73
  mndSetMsgHandle(pMnode, TDMT_SCH_MERGE_QUERY, mndProcessQueryMsg);
D
dapan1121 已提交
74 75
  mndSetMsgHandle(pMnode, TDMT_SCH_QUERY_CONTINUE, mndProcessQueryMsg);
  mndSetMsgHandle(pMnode, TDMT_SCH_FETCH, mndProcessQueryMsg);
D
dapan1121 已提交
76
  mndSetMsgHandle(pMnode, TDMT_SCH_MERGE_FETCH, mndProcessQueryMsg);
D
dapan1121 已提交
77 78
  mndSetMsgHandle(pMnode, TDMT_SCH_DROP_TASK, mndProcessQueryMsg);
  mndSetMsgHandle(pMnode, TDMT_SCH_QUERY_HEARTBEAT, mndProcessQueryMsg);
D
dapan1121 已提交
79 80 81 82 83

  return 0;
}

void mndCleanupQuery(SMnode *pMnode) { qWorkerDestroy((void **)&pMnode->pQuery); }