qnode.c 2.8 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * 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/>.
S
Shengliang Guan 已提交
14 15
 */

S
Shengliang Guan 已提交
16
#include "executor.h"
S
Shengliang Guan 已提交
17
#include "qndInt.h"
D
dapan1121 已提交
18 19
#include "query.h"
#include "qworker.h"
S
slzhou 已提交
20
#include "libs/function/function.h"
S
Shengliang Guan 已提交
21 22

SQnode *qndOpen(const SQnodeOpt *pOption) {
wafwerar's avatar
wafwerar 已提交
23
  SQnode *pQnode = taosMemoryCalloc(1, sizeof(SQnode));
D
dapan1121 已提交
24 25 26 27 28
  if (NULL == pQnode) {
    qError("calloc SQnode failed");
    return NULL;
  }

S
Shengliang Guan 已提交
29
  if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, NULL, (void **)&pQnode->pQuery, &pOption->msgCb)) {
wafwerar's avatar
wafwerar 已提交
30
    taosMemoryFreeClear(pQnode);
D
dapan1121 已提交
31 32
    return NULL;
  }
S
Shengliang Guan 已提交
33 34

  pQnode->msgCb = pOption->msgCb;
S
Shengliang Guan 已提交
35 36 37
  return pQnode;
}

S
Shengliang Guan 已提交
38
void qndClose(SQnode *pQnode) {
D
dapan1121 已提交
39
  qWorkerDestroy((void **)&pQnode->pQuery);
wafwerar's avatar
wafwerar 已提交
40
  taosMemoryFree(pQnode);
D
dapan1121 已提交
41
}
S
Shengliang Guan 已提交
42 43 44

int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }

S
Shengliang Guan 已提交
45
int32_t qndProcessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
S
Shengliang Guan 已提交
46
  int32_t     code = -1;
47
  SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
S
Shengliang Guan 已提交
48
  qTrace("message in qnode queue is processing");
D
dapan1121 已提交
49 50

  switch (pMsg->msgType) {
S
Shengliang Guan 已提交
51 52 53
    case TDMT_VND_QUERY:
      code = qWorkerProcessQueryMsg(&handle, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
54
    case TDMT_VND_QUERY_CONTINUE:
S
Shengliang Guan 已提交
55 56
      code = qWorkerProcessCQueryMsg(&handle, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
57
    case TDMT_VND_FETCH:
S
Shengliang Guan 已提交
58 59
      code = qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
60
    case TDMT_VND_FETCH_RSP:
S
Shengliang Guan 已提交
61 62
      code = qWorkerProcessFetchRsp(pQnode, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
63
    case TDMT_VND_RES_READY:
S
Shengliang Guan 已提交
64 65
      code = qWorkerProcessReadyMsg(pQnode, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
66
    case TDMT_VND_TASKS_STATUS:
S
Shengliang Guan 已提交
67 68
      code = qWorkerProcessStatusMsg(pQnode, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
69
    case TDMT_VND_CANCEL_TASK:
S
Shengliang Guan 已提交
70 71
      code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
72
    case TDMT_VND_DROP_TASK:
S
Shengliang Guan 已提交
73 74
      code = qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
75
    case TDMT_VND_TABLE_META:
S
Shengliang Guan 已提交
76 77
      // code =  vnodeGetTableMeta(pQnode, pMsg);
      // break;
D
dapan1121 已提交
78
    case TDMT_VND_CONSUME:
S
Shengliang Guan 已提交
79 80
      // code =  tqProcessConsumeReq(pQnode->pTq, pMsg);
      // break;
D
dapan1121 已提交
81
    case TDMT_VND_QUERY_HEARTBEAT:
S
Shengliang Guan 已提交
82 83
      code = qWorkerProcessHbMsg(pQnode, pQnode->pQuery, pMsg);
      break;
D
dapan1121 已提交
84
    default:
S
Shengliang Guan 已提交
85
      qError("unknown msg type:%d in qnode queue", pMsg->msgType);
S
Shengliang Guan 已提交
86
      terrno = TSDB_CODE_VND_APP_ERROR;
D
dapan1121 已提交
87
  }
S
Shengliang Guan 已提交
88 89 90

  if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS;
  return code;
D
dapan1121 已提交
91
}