qworkerMsg.c 17.6 KB
Newer Older
L
Liu Jicong 已提交
1 2
#include "qworkerMsg.h"
#include "dataSinkMgt.h"
D
dapan1121 已提交
3 4 5
#include "executor.h"
#include "planner.h"
#include "query.h"
L
Liu Jicong 已提交
6
#include "qworker.h"
D
dapan1121 已提交
7
#include "qworkerInt.h"
L
Liu Jicong 已提交
8
#include "tcommon.h"
D
dapan1121 已提交
9 10 11 12 13
#include "tmsg.h"
#include "tname.h"

int32_t qwMallocFetchRsp(int32_t length, SRetrieveTableRsp **rsp) {
  int32_t msgSize = sizeof(SRetrieveTableRsp) + length;
L
Liu Jicong 已提交
14

D
dapan1121 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27
  SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)rpcMallocCont(msgSize);
  if (NULL == pRsp) {
    qError("rpcMallocCont %d failed", msgSize);
    QW_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }

  memset(pRsp, 0, sizeof(SRetrieveTableRsp));

  *rsp = pRsp;

  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
28
void qwBuildFetchRsp(void *msg, SOutputData *input, int32_t len, bool qComplete) {
D
dapan1121 已提交
29
  SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)msg;
L
Liu Jicong 已提交
30

D
dapan1121 已提交
31
  rsp->useconds = htobe64(input->useconds);
D
dapan1121 已提交
32
  rsp->completed = qComplete;
D
dapan1121 已提交
33 34 35 36
  rsp->precision = input->precision;
  rsp->compressed = input->compressed;
  rsp->compLen = htonl(len);
  rsp->numOfRows = htonl(input->numOfRows);
37
  rsp->numOfCols = htonl(input->numOfCols);
D
dapan1121 已提交
38 39 40
}

void qwFreeFetchRsp(void *msg) {
D
dapan 已提交
41 42 43
  if (msg) {
    rpcFreeCont(msg);
  }
D
dapan1121 已提交
44 45
}

S
Shengliang Guan 已提交
46
int32_t qwBuildAndSendQueryRsp(SRpcHandleInfo *pConn, int32_t code) {
D
dapan1121 已提交
47
  SQueryTableRsp rsp = {.code = code};
L
Liu Jicong 已提交
48

D
dapan1121 已提交
49
  int32_t contLen = tSerializeSQueryTableRsp(NULL, 0, &rsp);
L
Liu Jicong 已提交
50
  void   *msg = rpcMallocCont(contLen);
D
dapan1121 已提交
51
  tSerializeSQueryTableRsp(msg, contLen, &rsp);
D
dapan1121 已提交
52 53

  SRpcMsg rpcRsp = {
L
Liu Jicong 已提交
54 55 56 57
      .msgType = TDMT_VND_QUERY_RSP,
      .pCont = msg,
      .contLen = contLen,
      .code = code,
58
      .info = *pConn,
D
dapan1121 已提交
59 60
  };

S
shm  
Shengliang Guan 已提交
61
  tmsgSendRsp(&rpcRsp);
D
dapan1121 已提交
62 63 64 65

  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
66
int32_t qwBuildAndSendReadyRsp(SRpcHandleInfo *pConn, int32_t code) {
D
dapan1121 已提交
67 68 69 70
  SResReadyRsp *pRsp = (SResReadyRsp *)rpcMallocCont(sizeof(SResReadyRsp));
  pRsp->code = code;

  SRpcMsg rpcRsp = {
L
Liu Jicong 已提交
71 72 73 74
      .msgType = TDMT_VND_RES_READY_RSP,
      .pCont = pRsp,
      .contLen = sizeof(*pRsp),
      .code = code,
75
      .info = *pConn,
D
dapan1121 已提交
76
  };
77
  rpcRsp.info.ahandle = NULL;
D
dapan1121 已提交
78

S
shm  
Shengliang Guan 已提交
79
  tmsgSendRsp(&rpcRsp);
D
dapan1121 已提交
80 81 82 83

  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
84
int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SExplainExecInfo *execInfo, int32_t num) {
D
dapan1121 已提交
85 86 87
  SExplainRsp rsp = {.numOfPlans = num, .subplanInfo = execInfo};

  int32_t contLen = tSerializeSExplainRsp(NULL, 0, &rsp);
L
Liu Jicong 已提交
88
  void   *pRsp = rpcMallocCont(contLen);
D
dapan1121 已提交
89 90 91
  tSerializeSExplainRsp(pRsp, contLen, &rsp);

  SRpcMsg rpcRsp = {
L
Liu Jicong 已提交
92 93 94 95
      .msgType = TDMT_VND_EXPLAIN_RSP,
      .pCont = pRsp,
      .contLen = contLen,
      .code = 0,
96
      .info = *pConn,
D
dapan1121 已提交
97
  };
98
  rpcRsp.info.ahandle = NULL;
D
dapan1121 已提交
99 100 101 102 103 104

  tmsgSendRsp(&rpcRsp);

  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
105
int32_t qwBuildAndSendHbRsp(SRpcHandleInfo *pConn, SSchedulerHbRsp *pStatus, int32_t code) {
D
dapan1121 已提交
106
  int32_t contLen = tSerializeSSchedulerHbRsp(NULL, 0, pStatus);
L
Liu Jicong 已提交
107
  void   *pRsp = rpcMallocCont(contLen);
D
dapan1121 已提交
108
  tSerializeSSchedulerHbRsp(pRsp, contLen, pStatus);
D
dapan1121 已提交
109 110

  SRpcMsg rpcRsp = {
L
Liu Jicong 已提交
111 112
      .msgType = TDMT_VND_QUERY_HEARTBEAT_RSP,
      .contLen = contLen,
113
      .pCont = pRsp,
L
Liu Jicong 已提交
114
      .code = code,
115
      .info = *pConn,
D
dapan1121 已提交
116 117
  };

S
shm  
Shengliang Guan 已提交
118
  tmsgSendRsp(&rpcRsp);
D
dapan1121 已提交
119 120 121 122

  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
123
int32_t qwBuildAndSendFetchRsp(SRpcHandleInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, int32_t code) {
D
dapan1121 已提交
124 125 126 127 128 129 130
  if (NULL == pRsp) {
    pRsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp));
    memset(pRsp, 0, sizeof(SRetrieveTableRsp));
    dataLength = 0;
  }

  SRpcMsg rpcRsp = {
L
Liu Jicong 已提交
131 132 133 134
      .msgType = TDMT_VND_FETCH_RSP,
      .pCont = pRsp,
      .contLen = sizeof(*pRsp) + dataLength,
      .code = code,
135
      .info = *pConn,
D
dapan1121 已提交
136 137
  };

S
shm  
Shengliang Guan 已提交
138
  tmsgSendRsp(&rpcRsp);
D
dapan1121 已提交
139 140 141 142

  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
143
int32_t qwBuildAndSendCancelRsp(SRpcHandleInfo *pConn, int32_t code) {
D
dapan1121 已提交
144 145 146 147
  STaskCancelRsp *pRsp = (STaskCancelRsp *)rpcMallocCont(sizeof(STaskCancelRsp));
  pRsp->code = code;

  SRpcMsg rpcRsp = {
L
Liu Jicong 已提交
148 149 150 151
      .msgType = TDMT_VND_CANCEL_TASK_RSP,
      .pCont = pRsp,
      .contLen = sizeof(*pRsp),
      .code = code,
152
      .info = *pConn,
D
dapan1121 已提交
153 154
  };

S
shm  
Shengliang Guan 已提交
155
  tmsgSendRsp(&rpcRsp);
D
dapan1121 已提交
156 157 158
  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
159
int32_t qwBuildAndSendDropRsp(SRpcHandleInfo *pConn, int32_t code) {
D
dapan1121 已提交
160 161 162 163
  STaskDropRsp *pRsp = (STaskDropRsp *)rpcMallocCont(sizeof(STaskDropRsp));
  pRsp->code = code;

  SRpcMsg rpcRsp = {
L
Liu Jicong 已提交
164 165 166 167
      .msgType = TDMT_VND_DROP_TASK_RSP,
      .pCont = pRsp,
      .contLen = sizeof(*pRsp),
      .code = code,
168
      .info = *pConn,
D
dapan1121 已提交
169 170
  };

S
shm  
Shengliang Guan 已提交
171
  tmsgSendRsp(&rpcRsp);
D
dapan1121 已提交
172 173 174
  return TSDB_CODE_SUCCESS;
}

S
shm  
Shengliang Guan 已提交
175
int32_t qwBuildAndSendShowRsp(SRpcMsg *pMsg, int32_t code) {
S
Shengliang Guan 已提交
176 177 178 179
  int32_t         numOfCols = 6;
  SVShowTablesRsp showRsp = {0};

  // showRsp.showId = 1;
wafwerar's avatar
wafwerar 已提交
180
  showRsp.tableMeta.pSchemas = taosMemoryCalloc(numOfCols, sizeof(SSchema));
S
Shengliang Guan 已提交
181 182 183 184
  if (showRsp.tableMeta.pSchemas == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }
D
dapan1121 已提交
185

L
Liu Jicong 已提交
186
  col_id_t cols = 0;
S
Shengliang Guan 已提交
187
  SSchema *pSchema = showRsp.tableMeta.pSchemas;
D
dapan1121 已提交
188 189

  const SSchema *s = tGetTbnameColumnSchema();
S
Shengliang Guan 已提交
190
  *pSchema = createSchema(s->type, s->bytes, ++cols, "name");
D
dapan1121 已提交
191 192 193
  pSchema++;

  int32_t type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
194
  *pSchema = createSchema(type, tDataTypes[type].bytes, ++cols, "created");
D
dapan1121 已提交
195 196 197
  pSchema++;

  type = TSDB_DATA_TYPE_SMALLINT;
S
Shengliang Guan 已提交
198
  *pSchema = createSchema(type, tDataTypes[type].bytes, ++cols, "columns");
D
dapan1121 已提交
199 200
  pSchema++;

S
Shengliang Guan 已提交
201
  *pSchema = createSchema(s->type, s->bytes, ++cols, "stable");
D
dapan1121 已提交
202 203 204
  pSchema++;

  type = TSDB_DATA_TYPE_BIGINT;
S
Shengliang Guan 已提交
205
  *pSchema = createSchema(type, tDataTypes[type].bytes, ++cols, "uid");
D
dapan1121 已提交
206 207 208
  pSchema++;

  type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
209
  *pSchema = createSchema(type, tDataTypes[type].bytes, ++cols, "vgId");
D
dapan1121 已提交
210 211

  assert(cols == numOfCols);
S
Shengliang Guan 已提交
212 213 214 215 216
  showRsp.tableMeta.numOfColumns = cols;

  int32_t bufLen = tSerializeSShowRsp(NULL, 0, &showRsp);
  void   *pBuf = rpcMallocCont(bufLen);
  tSerializeSShowRsp(pBuf, bufLen, &showRsp);
D
dapan1121 已提交
217 218

  SRpcMsg rpcMsg = {
S
Shengliang Guan 已提交
219
      .info = pMsg->info,
S
Shengliang Guan 已提交
220 221 222
      .pCont = pBuf,
      .contLen = bufLen,
      .code = code,
D
dapan1121 已提交
223 224
  };

S
shm  
Shengliang Guan 已提交
225
  tmsgSendRsp(&rpcMsg);
D
dapan1121 已提交
226 227 228
  return TSDB_CODE_SUCCESS;
}

L
Liu Jicong 已提交
229
int32_t qwBuildAndSendShowFetchRsp(SRpcMsg *pMsg, SVShowTablesFetchReq *pFetchReq) {
D
dapan1121 已提交
230
  SVShowTablesFetchRsp *pRsp = (SVShowTablesFetchRsp *)rpcMallocCont(sizeof(SVShowTablesFetchRsp));
L
Liu Jicong 已提交
231
  int32_t               handle = htonl(pFetchReq->id);
D
dapan1121 已提交
232 233 234

  pRsp->numOfRows = 0;
  SRpcMsg rpcMsg = {
S
Shengliang Guan 已提交
235
      .info = pMsg->info,
L
Liu Jicong 已提交
236
      .pCont = pRsp,
D
dapan1121 已提交
237
      .contLen = sizeof(*pRsp),
L
Liu Jicong 已提交
238
      .code = 0,
D
dapan1121 已提交
239 240
  };

S
shm  
Shengliang Guan 已提交
241
  tmsgSendRsp(&rpcMsg);
D
dapan1121 已提交
242 243 244
  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
245
int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) {
L
Liu Jicong 已提交
246
  SQueryContinueReq *req = (SQueryContinueReq *)rpcMallocCont(sizeof(SQueryContinueReq));
D
dapan1121 已提交
247 248 249 250 251 252 253 254 255 256 257
  if (NULL == req) {
    QW_SCH_TASK_ELOG("rpcMallocCont %d failed", (int32_t)sizeof(SQueryContinueReq));
    QW_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }

  req->header.vgId = mgmt->nodeId;
  req->sId = sId;
  req->queryId = qId;
  req->taskId = tId;

  SRpcMsg pNewMsg = {
L
Liu Jicong 已提交
258 259 260 261
      .msgType = TDMT_VND_QUERY_CONTINUE,
      .pCont = req,
      .contLen = sizeof(SQueryContinueReq),
      .code = 0,
262
      .info = *pConn,
D
dapan1121 已提交
263 264
  };

S
Shengliang Guan 已提交
265
  int32_t code = tmsgPutToQueue(&mgmt->msgCb, QUERY_QUEUE, &pNewMsg);
D
dapan1121 已提交
266
  if (TSDB_CODE_SUCCESS != code) {
H
Haojun Liao 已提交
267
    QW_SCH_TASK_ELOG("put query continue msg to queue failed, vgId:%d, code:%s", mgmt->nodeId, tstrerror(code));
D
dapan1121 已提交
268 269 270 271
    rpcFreeCont(req);
    QW_ERR_RET(code);
  }

D
dapan1121 已提交
272
  QW_SCH_TASK_DLOG("query continue msg put to queue, vgId:%d", mgmt->nodeId);
D
dapan1121 已提交
273 274 275 276

  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
277
int32_t qwRegisterQueryBrokenLinkArg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) {
L
Liu Jicong 已提交
278
  STaskDropReq *req = (STaskDropReq *)rpcMallocCont(sizeof(STaskDropReq));
D
dapan1121 已提交
279 280 281
  if (NULL == req) {
    QW_SCH_TASK_ELOG("rpcMallocCont %d failed", (int32_t)sizeof(STaskDropReq));
    QW_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
L
Liu Jicong 已提交
282
  }
D
dapan1121 已提交
283

D
dapan1121 已提交
284 285 286 287 288
  req->header.vgId = htonl(mgmt->nodeId);
  req->sId = htobe64(sId);
  req->queryId = htobe64(qId);
  req->taskId = htobe64(tId);
  req->refId = htobe64(rId);
L
Liu Jicong 已提交
289

S
Shengliang Guan 已提交
290
  SRpcMsg brokenMsg = {
L
Liu Jicong 已提交
291 292 293 294
      .msgType = TDMT_VND_DROP_TASK,
      .pCont = req,
      .contLen = sizeof(STaskDropReq),
      .code = TSDB_CODE_RPC_NETWORK_UNAVAIL,
295
      .info = *pConn,
D
dapan1121 已提交
296
  };
L
Liu Jicong 已提交
297

S
Shengliang Guan 已提交
298
  tmsgRegisterBrokenLinkArg(&brokenMsg);
D
dapan1121 已提交
299 300 301 302

  return TSDB_CODE_SUCCESS;
}

S
Shengliang Guan 已提交
303
int32_t qwRegisterHbBrokenLinkArg(SQWorker *mgmt, uint64_t sId, SRpcHandleInfo *pConn) {
D
dapan1121 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
  SSchedulerHbReq req = {0};
  req.header.vgId = mgmt->nodeId;
  req.sId = sId;

  int32_t msgSize = tSerializeSSchedulerHbReq(NULL, 0, &req);
  if (msgSize < 0) {
    QW_SCH_ELOG("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize);
    QW_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }
  void *msg = rpcMallocCont(msgSize);
  if (NULL == msg) {
    QW_SCH_ELOG("calloc %d failed", msgSize);
    QW_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }
  if (tSerializeSSchedulerHbReq(msg, msgSize, &req) < 0) {
    QW_SCH_ELOG("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize);
    taosMemoryFree(msg);
    QW_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
  }
L
Liu Jicong 已提交
323

S
Shengliang Guan 已提交
324
  SRpcMsg brokenMsg = {
L
Liu Jicong 已提交
325 326 327 328
      .msgType = TDMT_VND_QUERY_HEARTBEAT,
      .pCont = msg,
      .contLen = msgSize,
      .code = TSDB_CODE_RPC_NETWORK_UNAVAIL,
329
      .info = *pConn,
D
dapan1121 已提交
330
  };
L
Liu Jicong 已提交
331

S
Shengliang Guan 已提交
332
  tmsgRegisterBrokenLinkArg(&brokenMsg);
D
dapan1121 已提交
333 334 335 336

  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
337 338 339 340 341
int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
  }

L
Liu Jicong 已提交
342
  int32_t       code = 0;
D
dapan1121 已提交
343
  SSubQueryMsg *msg = pMsg->pCont;
D
dapan1121 已提交
344
  SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
L
Liu Jicong 已提交
345

D
dapan1121 已提交
346
  if (NULL == msg || pMsg->contLen <= sizeof(*msg)) {
D
dapan1121 已提交
347
    QW_ELOG("invalid query msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
D
dapan1121 已提交
348
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
D
dapan1121 已提交
349 350
  }

L
Liu Jicong 已提交
351
  msg->sId = be64toh(msg->sId);
D
dapan1121 已提交
352
  msg->queryId = be64toh(msg->queryId);
L
Liu Jicong 已提交
353 354 355 356
  msg->taskId = be64toh(msg->taskId);
  msg->refId = be64toh(msg->refId);
  msg->phyLen = ntohl(msg->phyLen);
  msg->sqlLen = ntohl(msg->sqlLen);
357

D
dapan1121 已提交
358 359 360
  uint64_t sId = msg->sId;
  uint64_t qId = msg->queryId;
  uint64_t tId = msg->taskId;
D
dapan1121 已提交
361
  int64_t  rId = msg->refId;
D
dapan1121 已提交
362

363 364
  SQWMsg qwMsg = {.node = node, .msg = msg->msg + msg->sqlLen, .msgLen = msg->phyLen, .connInfo = pMsg->info};
  char  *sql = strndup(msg->msg, msg->sqlLen);
S
Shengliang Guan 已提交
365
  QW_SCH_TASK_DLOG("processQuery start, node:%p, handle:%p, sql:%s", node, pMsg->info.handle, sql);
wafwerar's avatar
wafwerar 已提交
366
  taosMemoryFreeClear(sql);
367

D
dapan1121 已提交
368
  QW_ERR_RET(qwProcessQuery(QW_FPARAMS(), &qwMsg, msg->taskType, msg->explain));
369

D
dapan1121 已提交
370
  QW_SCH_TASK_DLOG("processQuery end, node:%p", node);
371

L
Liu Jicong 已提交
372
  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
373 374
}

375
int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
L
Liu Jicong 已提交
376 377 378
  int32_t            code = 0;
  int8_t             status = 0;
  bool               queryDone = false;
379
  SQueryContinueReq *msg = (SQueryContinueReq *)pMsg->pCont;
L
Liu Jicong 已提交
380 381
  bool               needStop = false;
  SQWTaskCtx        *handles = NULL;
D
dapan1121 已提交
382
  SQWorker      *mgmt = (SQWorker *)qWorkerMgmt;
D
dapan1121 已提交
383

D
dapan1121 已提交
384
  if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
D
dapan1121 已提交
385
    QW_ELOG("invalid cquery msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
D
dapan1121 已提交
386
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
D
dapan1121 已提交
387 388
  }

389 390 391
  uint64_t sId = msg->sId;
  uint64_t qId = msg->queryId;
  uint64_t tId = msg->taskId;
L
Liu Jicong 已提交
392
  int64_t  rId = 0;
D
dapan1121 已提交
393

394
  SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connInfo = pMsg->info};
D
dapan1121 已提交
395

S
Shengliang Guan 已提交
396
  QW_SCH_TASK_DLOG("processCQuery start, node:%p, handle:%p", node, pMsg->info.handle);
397 398 399

  QW_ERR_RET(qwProcessCQuery(QW_FPARAMS(), &qwMsg));

D
dapan1121 已提交
400
  QW_SCH_TASK_DLOG("processCQuery end, node:%p", node);
401

L
Liu Jicong 已提交
402
  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
403 404
}

L
Liu Jicong 已提交
405
int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
D
dapan1121 已提交
406 407 408 409
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    return TSDB_CODE_QRY_INVALID_INPUT;
  }

D
dapan1121 已提交
410
  SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
D
dapan1121 已提交
411 412
  SResReadyReq *msg = pMsg->pCont;
  if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
D
dapan1121 已提交
413
    QW_ELOG("invalid task ready msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
D
dapan1121 已提交
414
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
L
Liu Jicong 已提交
415
  }
D
dapan1121 已提交
416

D
dapan1121 已提交
417 418 419 420 421 422 423
  msg->sId = be64toh(msg->sId);
  msg->queryId = be64toh(msg->queryId);
  msg->taskId = be64toh(msg->taskId);

  uint64_t sId = msg->sId;
  uint64_t qId = msg->queryId;
  uint64_t tId = msg->taskId;
L
Liu Jicong 已提交
424
  int64_t  rId = 0;
D
dapan1121 已提交
425

426
  SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connInfo = pMsg->info};
D
dapan1121 已提交
427

S
Shengliang Guan 已提交
428
  QW_SCH_TASK_DLOG("processReady start, node:%p, handle:%p", node, pMsg->info.handle);
429

D
dapan1121 已提交
430
  QW_ERR_RET(qwProcessReady(QW_FPARAMS(), &qwMsg));
431

D
dapan1121 已提交
432
  QW_SCH_TASK_DLOG("processReady end, node:%p", node);
L
Liu Jicong 已提交
433

D
dapan1121 已提交
434 435 436 437 438 439 440 441
  return TSDB_CODE_SUCCESS;
}

int32_t qWorkerProcessStatusMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    return TSDB_CODE_QRY_INVALID_INPUT;
  }

L
Liu Jicong 已提交
442
  int32_t             code = 0;
D
dapan1121 已提交
443 444 445 446
  SSchTasksStatusReq *msg = pMsg->pCont;
  if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
    qError("invalid task status msg");
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
L
Liu Jicong 已提交
447
  }
D
dapan1121 已提交
448

D
dapan1121 已提交
449
  SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
D
dapan1121 已提交
450
  msg->sId = htobe64(msg->sId);
D
dapan1121 已提交
451
  uint64_t sId = msg->sId;
D
dapan1121 已提交
452 453

  SSchedulerStatusRsp *sStatus = NULL;
L
Liu Jicong 已提交
454 455

  // QW_ERR_JRET(qwGetSchTasksStatus(qWorkerMgmt, msg->sId, &sStatus));
D
dapan1121 已提交
456 457 458

_return:

L
Liu Jicong 已提交
459
  // QW_ERR_RET(qwBuildAndSendStatusRsp(pMsg, sStatus));
D
dapan1121 已提交
460 461 462 463 464 465 466 467 468 469

  return TSDB_CODE_SUCCESS;
}

int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    return TSDB_CODE_QRY_INVALID_INPUT;
  }

  SResFetchReq *msg = pMsg->pCont;
D
dapan1121 已提交
470
  SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
L
Liu Jicong 已提交
471

D
dapan1121 已提交
472
  if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
L
Liu Jicong 已提交
473
    QW_ELOG("invalid fetch msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
D
dapan1121 已提交
474
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
L
Liu Jicong 已提交
475
  }
D
dapan1121 已提交
476

D
dapan1121 已提交
477 478 479
  msg->sId = be64toh(msg->sId);
  msg->queryId = be64toh(msg->queryId);
  msg->taskId = be64toh(msg->taskId);
D
dapan1121 已提交
480 481 482 483

  uint64_t sId = msg->sId;
  uint64_t qId = msg->queryId;
  uint64_t tId = msg->taskId;
L
Liu Jicong 已提交
484
  int64_t  rId = 0;
D
dapan1121 已提交
485

486
  SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connInfo = pMsg->info};
D
dapan1121 已提交
487

S
Shengliang Guan 已提交
488
  QW_SCH_TASK_DLOG("processFetch start, node:%p, handle:%p", node, pMsg->info.handle);
489 490 491

  QW_ERR_RET(qwProcessFetch(QW_FPARAMS(), &qwMsg));

D
dapan1121 已提交
492
  QW_SCH_TASK_DLOG("processFetch end, node:%p", node);
493

L
Liu Jicong 已提交
494
  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
495 496
}

S
Shengliang 已提交
497
int32_t qWorkerProcessFetchRsp(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
S
Shengliang Guan 已提交
498
  qProcessFetchRsp(NULL, pMsg, NULL);
499
  pMsg->pCont = NULL;
S
Shengliang 已提交
500 501 502
  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
503 504 505 506 507
int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    return TSDB_CODE_QRY_INVALID_INPUT;
  }

D
dapan1121 已提交
508
  SQWorker   *mgmt = (SQWorker *)qWorkerMgmt;
L
Liu Jicong 已提交
509
  int32_t         code = 0;
D
dapan1121 已提交
510 511
  STaskCancelReq *msg = pMsg->pCont;
  if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
L
Liu Jicong 已提交
512
    qError("invalid task cancel msg");
D
dapan1121 已提交
513
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
L
Liu Jicong 已提交
514
  }
D
dapan1121 已提交
515

D
dapan1121 已提交
516 517 518 519
  msg->sId = be64toh(msg->sId);
  msg->queryId = be64toh(msg->queryId);
  msg->taskId = be64toh(msg->taskId);
  msg->refId = be64toh(msg->refId);
D
dapan1121 已提交
520

D
dapan1121 已提交
521 522 523 524 525
  uint64_t sId = msg->sId;
  uint64_t qId = msg->queryId;
  uint64_t tId = msg->taskId;
  int64_t  rId = msg->refId;

526
  SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connInfo = pMsg->info};
D
dapan1121 已提交
527

L
Liu Jicong 已提交
528
  // QW_ERR_JRET(qwCancelTask(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId));
D
dapan1121 已提交
529 530 531

_return:

S
shm  
Shengliang Guan 已提交
532
  QW_ERR_RET(qwBuildAndSendCancelRsp(&qwMsg.connInfo, code));
D
dapan1121 已提交
533
  QW_SCH_TASK_DLOG("cancel rsp send, handle:%p, code:%x - %s", qwMsg.connInfo.handle, code, tstrerror(code));
D
dapan1121 已提交
534 535 536 537 538 539 540 541 542

  return TSDB_CODE_SUCCESS;
}

int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    return TSDB_CODE_QRY_INVALID_INPUT;
  }

L
Liu Jicong 已提交
543
  int32_t       code = 0;
D
dapan1121 已提交
544
  STaskDropReq *msg = pMsg->pCont;
D
dapan1121 已提交
545
  SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
L
Liu Jicong 已提交
546

D
dapan1121 已提交
547
  if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
D
dapan1121 已提交
548
    QW_ELOG("invalid task drop msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
D
dapan1121 已提交
549
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
L
Liu Jicong 已提交
550
  }
D
dapan1121 已提交
551

D
dapan1121 已提交
552 553 554
  msg->sId = be64toh(msg->sId);
  msg->queryId = be64toh(msg->queryId);
  msg->taskId = be64toh(msg->taskId);
D
dapan1121 已提交
555
  msg->refId = be64toh(msg->refId);
D
dapan1121 已提交
556 557 558 559

  uint64_t sId = msg->sId;
  uint64_t qId = msg->queryId;
  uint64_t tId = msg->taskId;
D
dapan1121 已提交
560
  int64_t  rId = msg->refId;
D
dapan1121 已提交
561

562
  SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .code = pMsg->code, .connInfo = pMsg->info};
D
dapan1121 已提交
563

D
dapan1121 已提交
564
  if (TSDB_CODE_RPC_NETWORK_UNAVAIL == pMsg->code) {
L
Liu Jicong 已提交
565
    QW_SCH_TASK_DLOG("receive drop task due to network broken, error:%s", tstrerror(pMsg->code));
D
dapan1121 已提交
566
  }
D
dapan1121 已提交
567

S
Shengliang Guan 已提交
568
  QW_SCH_TASK_DLOG("processDrop start, node:%p, handle:%p", node, pMsg->info.handle);
569 570 571

  QW_ERR_RET(qwProcessDrop(QW_FPARAMS(), &qwMsg));

D
dapan1121 已提交
572
  QW_SCH_TASK_DLOG("processDrop end, node:%p", node);
573 574

  return TSDB_CODE_SUCCESS;
D
dapan1121 已提交
575 576
}

D
dapan1121 已提交
577 578 579 580 581
int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    return TSDB_CODE_QRY_INVALID_INPUT;
  }

L
Liu Jicong 已提交
582
  int32_t         code = 0;
D
dapan1121 已提交
583
  SSchedulerHbReq req = {0};
D
dapan1121 已提交
584
  SQWorker   *mgmt = (SQWorker *)qWorkerMgmt;
L
Liu Jicong 已提交
585

D
dapan1121 已提交
586 587 588
  if (NULL == pMsg->pCont) {
    QW_ELOG("invalid hb msg, msg:%p, msgLen:%d", pMsg->pCont, pMsg->contLen);
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
L
Liu Jicong 已提交
589
  }
D
dapan1121 已提交
590 591 592 593 594 595 596 597

  if (tDeserializeSSchedulerHbReq(pMsg->pCont, pMsg->contLen, &req)) {
    QW_ELOG("invalid hb msg, msg:%p, msgLen:%d", pMsg->pCont, pMsg->contLen);
    tFreeSSchedulerHbReq(&req);
    QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
  }

  uint64_t sId = req.sId;
598
  SQWMsg   qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .code = pMsg->code, .connInfo = pMsg->info};
D
dapan1121 已提交
599
  if (TSDB_CODE_RPC_NETWORK_UNAVAIL == pMsg->code) {
L
Liu Jicong 已提交
600
    QW_SCH_DLOG("receive Hb msg due to network broken, error:%s", tstrerror(pMsg->code));
D
dapan1121 已提交
601 602
  }

S
Shengliang Guan 已提交
603
  QW_SCH_DLOG("processHb start, node:%p, handle:%p", node, pMsg->info.handle);
D
dapan1121 已提交
604 605 606 607 608 609 610 611

  QW_ERR_RET(qwProcessHb(mgmt, &qwMsg, &req));

  QW_SCH_DLOG("processHb end, node:%p", node);

  return TSDB_CODE_SUCCESS;
}

D
dapan1121 已提交
612 613 614 615 616
int32_t qWorkerProcessShowMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    return TSDB_CODE_QRY_INVALID_INPUT;
  }

L
Liu Jicong 已提交
617
  int32_t          code = 0;
D
dapan1121 已提交
618
  SVShowTablesReq *pReq = pMsg->pCont;
S
shm  
Shengliang Guan 已提交
619
  QW_RET(qwBuildAndSendShowRsp(pMsg, code));
D
dapan1121 已提交
620 621 622 623 624 625 626 627
}

int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
  if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
    return TSDB_CODE_QRY_INVALID_INPUT;
  }

  SVShowTablesFetchReq *pFetchReq = pMsg->pCont;
S
shm  
Shengliang Guan 已提交
628
  QW_RET(qwBuildAndSendShowFetchRsp(pMsg, pFetchReq));
D
dapan1121 已提交
629
}