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

D
dapan1121 已提交
21 22 23 24 25 26 27 28
int32_t mndPreprocessQueryMsg(SMnode * pMnode, SRpcMsg * pMsg) {
  if (TDMT_VND_QUERY != pMsg->msgType) {
    return 0;
  }

  return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg);
}

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

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

  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
  return code;
D
dapan1121 已提交
58 59 60
}

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

  mndSetMsgHandle(pMnode, TDMT_VND_QUERY, mndProcessQueryMsg);
  mndSetMsgHandle(pMnode, TDMT_VND_QUERY_CONTINUE, mndProcessQueryMsg);
S
Shengliang Guan 已提交
68 69 70
  mndSetMsgHandle(pMnode, TDMT_VND_FETCH, mndProcessQueryMsg);
  mndSetMsgHandle(pMnode, TDMT_VND_DROP_TASK, mndProcessQueryMsg);
  mndSetMsgHandle(pMnode, TDMT_VND_QUERY_HEARTBEAT, mndProcessQueryMsg);
D
dapan1121 已提交
71 72 73 74 75

  return 0;
}

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