mndQuery.c 2.3 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"

S
Shengliang Guan 已提交
21
int32_t mndProcessQueryMsg(SRpcMsg *pMsg) {
S
Shengliang Guan 已提交
22
  int32_t     code = -1;
S
Shengliang Guan 已提交
23
  SMnode     *pMnode = pMsg->info.node;
24
  SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb};
D
dapan1121 已提交
25

S
Shengliang Guan 已提交
26 27
  mTrace("msg:%p, in query queue is processing", pMsg);
  switch (pMsg->msgType) {
D
dapan1121 已提交
28
    case TDMT_VND_QUERY:
S
Shengliang Guan 已提交
29
      code = qWorkerProcessQueryMsg(&handle, pMnode->pQuery, pMsg);
S
Shengliang Guan 已提交
30
      break;
D
dapan1121 已提交
31
    case TDMT_VND_QUERY_CONTINUE:
S
Shengliang Guan 已提交
32
      code = qWorkerProcessCQueryMsg(&handle, pMnode->pQuery, pMsg);
S
Shengliang Guan 已提交
33
      break;
D
dapan1121 已提交
34
    case TDMT_VND_FETCH:
S
Shengliang Guan 已提交
35 36
      code = qWorkerProcessFetchMsg(pMnode, pMnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
37
    case TDMT_VND_DROP_TASK:
S
Shengliang Guan 已提交
38 39
      code = qWorkerProcessDropMsg(pMnode, pMnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
40
    case TDMT_VND_QUERY_HEARTBEAT:
S
Shengliang Guan 已提交
41 42
      code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
43
    default:
S
Shengliang Guan 已提交
44
      terrno = TSDB_CODE_VND_APP_ERROR;
S
Shengliang Guan 已提交
45
      mError("unknown msg type:%d in query queue", pMsg->msgType);
D
dapan1121 已提交
46
  }
S
Shengliang Guan 已提交
47 48 49

  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
  return code;
D
dapan1121 已提交
50 51 52
}

int32_t mndInitQuery(SMnode *pMnode) {
S
Shengliang Guan 已提交
53
  if (qWorkerInit(NODE_TYPE_MNODE, MNODE_HANDLE, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb) != 0) {
S
Shengliang Guan 已提交
54 55
    mError("failed to init qworker in mnode since %s", terrstr());
    return -1;
D
dapan1121 已提交
56 57 58 59
  }

  mndSetMsgHandle(pMnode, TDMT_VND_QUERY, mndProcessQueryMsg);
  mndSetMsgHandle(pMnode, TDMT_VND_QUERY_CONTINUE, mndProcessQueryMsg);
S
Shengliang Guan 已提交
60 61 62
  mndSetMsgHandle(pMnode, TDMT_VND_FETCH, mndProcessQueryMsg);
  mndSetMsgHandle(pMnode, TDMT_VND_DROP_TASK, mndProcessQueryMsg);
  mndSetMsgHandle(pMnode, TDMT_VND_QUERY_HEARTBEAT, mndProcessQueryMsg);
D
dapan1121 已提交
63 64 65 66 67

  return 0;
}

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