qnode.c 3.6 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

D
dapan1121 已提交
43
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { 
D
dapan1121 已提交
44 45 46 47 48 49 50
  SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
  SQWorkerStat stat = {0};

  int32_t code = qWorkerGetStat(&handle, pQnode->pQuery, &stat);
  if (code) {
    return code;
  }
S
Shengliang Guan 已提交
51

D
dapan1121 已提交
52 53 54 55 56 57 58 59 60 61
  pLoad->numOfQueryInQueue = stat.numOfQueryInQueue;
  pLoad->numOfFetchInQueue = stat.numOfFetchInQueue;
  pLoad->timeInQueryQueue = stat.timeInQueryQueue;
  pLoad->timeInFetchQueue = stat.timeInFetchQueue;
  pLoad->cacheDataSize = stat.cacheDataSize;
  pLoad->numOfProcessedQuery = stat.queryProcessed;
  pLoad->numOfProcessedCQuery = stat.cqueryProcessed;
  pLoad->numOfProcessedFetch = stat.fetchProcessed;
  pLoad->numOfProcessedDrop = stat.dropProcessed;
  pLoad->numOfProcessedHb = stat.hbProcessed;
D
dapan1121 已提交
62
  pLoad->numOfProcessedDelete = stat.deleteProcessed;
D
dapan1121 已提交
63 64 65 66
  
  return 0; 
}

D
dapan1121 已提交
67
int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg * pMsg) {
D
dapan1121 已提交
68
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
D
dapan1121 已提交
69 70 71 72 73 74
    return 0;
  }

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

D
dapan1121 已提交
75
int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg) {
S
Shengliang Guan 已提交
76
  int32_t     code = -1;
77
  SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
S
Shengliang Guan 已提交
78
  qTrace("message in qnode queue is processing");
D
dapan1121 已提交
79 80

  switch (pMsg->msgType) {
D
dapan1121 已提交
81
    case TDMT_SCH_QUERY:
D
dapan1121 已提交
82
    case TDMT_SCH_MERGE_QUERY:
D
dapan1121 已提交
83
      code = qWorkerProcessQueryMsg(&handle, pQnode->pQuery, pMsg, ts);
S
Shengliang Guan 已提交
84
      break;
D
dapan1121 已提交
85
    case TDMT_SCH_QUERY_CONTINUE:
D
dapan1121 已提交
86
      code = qWorkerProcessCQueryMsg(&handle, pQnode->pQuery, pMsg, ts);
S
Shengliang Guan 已提交
87
      break;
D
dapan1121 已提交
88
    case TDMT_SCH_FETCH:
L
Liu Jicong 已提交
89
    case TDMT_SCH_MERGE_FETCH:
D
dapan1121 已提交
90
      code = qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg, ts);
S
Shengliang Guan 已提交
91
      break;
D
dapan1121 已提交
92
    case TDMT_SCH_FETCH_RSP:
D
dapan1121 已提交
93
      code = qWorkerProcessFetchRsp(pQnode, pQnode->pQuery, pMsg, ts);
S
Shengliang Guan 已提交
94
      break;
D
dapan1121 已提交
95
    case TDMT_SCH_CANCEL_TASK:
D
dapan1121 已提交
96
      code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg, ts);
S
Shengliang Guan 已提交
97
      break;
D
dapan1121 已提交
98
    case TDMT_SCH_DROP_TASK:
D
dapan1121 已提交
99
      code = qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg, ts);
S
Shengliang Guan 已提交
100
      break;
D
dapan1121 已提交
101
    case TDMT_VND_CONSUME:
S
Shengliang Guan 已提交
102 103
      // code =  tqProcessConsumeReq(pQnode->pTq, pMsg);
      // break;
D
dapan1121 已提交
104
    case TDMT_SCH_QUERY_HEARTBEAT:
D
dapan1121 已提交
105
      code = qWorkerProcessHbMsg(pQnode, pQnode->pQuery, pMsg, ts);
S
Shengliang Guan 已提交
106
      break;
D
dapan1121 已提交
107
    default:
S
Shengliang Guan 已提交
108
      qError("unknown msg type:%d in qnode queue", pMsg->msgType);
S
Shengliang Guan 已提交
109
      terrno = TSDB_CODE_VND_APP_ERROR;
D
dapan1121 已提交
110
  }
S
Shengliang Guan 已提交
111 112 113

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