qnode.c 2.9 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) {
D
dapan 已提交
46
  qTrace("message in qnode query queue is processing");
47
  SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
D
dapan1121 已提交
48 49

  switch (pMsg->msgType) {
S
Shengliang Guan 已提交
50
    case TDMT_VND_QUERY: {
D
dapan1121 已提交
51 52 53 54 55
      return qWorkerProcessQueryMsg(&handle, pQnode->pQuery, pMsg);
    }
    case TDMT_VND_QUERY_CONTINUE:
      return qWorkerProcessCQueryMsg(&handle, pQnode->pQuery, pMsg);
    default:
D
dapan1121 已提交
56
      qError("unknown msg type:%d in query queue", pMsg->msgType);
D
dapan1121 已提交
57 58 59 60
      return TSDB_CODE_VND_APP_ERROR;
  }
}

S
Shengliang Guan 已提交
61
int32_t qndProcessFetchMsg(SQnode *pQnode, SRpcMsg *pMsg) {
D
dapan1121 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  qTrace("message in fetch queue is processing");
  switch (pMsg->msgType) {
    case TDMT_VND_FETCH:
      return qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg);
    case TDMT_VND_FETCH_RSP:
      return qWorkerProcessFetchRsp(pQnode, pQnode->pQuery, pMsg);
    case TDMT_VND_RES_READY:
      return qWorkerProcessReadyMsg(pQnode, pQnode->pQuery, pMsg);
    case TDMT_VND_TASKS_STATUS:
      return qWorkerProcessStatusMsg(pQnode, pQnode->pQuery, pMsg);
    case TDMT_VND_CANCEL_TASK:
      return qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg);
    case TDMT_VND_DROP_TASK:
      return qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg);
    case TDMT_VND_TABLE_META:
S
Shengliang Guan 已提交
77
      // return vnodeGetTableMeta(pQnode, pMsg);
D
dapan1121 已提交
78
    case TDMT_VND_CONSUME:
S
Shengliang Guan 已提交
79
      // return tqProcessConsumeReq(pQnode->pTq, pMsg);
D
dapan1121 已提交
80 81
    case TDMT_VND_QUERY_HEARTBEAT:
      return qWorkerProcessHbMsg(pQnode, pQnode->pQuery, pMsg);      
D
dapan1121 已提交
82
    default:
D
dapan1121 已提交
83
      qError("unknown msg type:%d in fetch queue", pMsg->msgType);
D
dapan1121 已提交
84 85 86
      return TSDB_CODE_VND_APP_ERROR;
  }
}