• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3798

31 Mar 2025 10:39AM UTC coverage: 9.424% (-20.9%) from 30.372%
#3798

push

travis-ci

happyguoxy
test:add test cases

21549 of 307601 branches covered (7.01%)

Branch coverage included in aggregate %.

36084 of 303967 relevant lines covered (11.87%)

58620.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http:www.gnu.org/licenses/>.
14
 */
15

16
#define _DEFAULT_SOURCE
17
#include "qmInt.h"
18

19
static inline void qmSendRsp(SRpcMsg *pMsg, int32_t code) {
×
20
  SRpcMsg rsp = {
×
21
      .code = code,
22
      .pCont = pMsg->info.rsp,
×
23
      .contLen = pMsg->info.rspLen,
×
24
      .info = pMsg->info,
25
  };
26
  tmsgSendRsp(&rsp);
×
27
}
×
28

29
static void qmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
×
30
  SQnodeMgmt *pMgmt = pInfo->ahandle;
×
31
  dTrace("msg:%p, get from qnode queue", pMsg);
×
32

33
  int32_t code = qndProcessQueryMsg(pMgmt->pQnode, pInfo, pMsg);
×
34
  if (IsReq(pMsg) && code != TSDB_CODE_ACTION_IN_PROGRESS) {
×
35
    if (code != 0 && terrno != 0) code = terrno;
×
36
    qmSendRsp(pMsg, code);
×
37
  }
38

39
  dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
×
40
  rpcFreeCont(pMsg->pCont);
×
41
  taosFreeQitem(pMsg);
×
42
}
×
43

44
static int32_t qmPutNodeMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pMsg) {
×
45
  dTrace("msg:%p, put into worker %s, type:%s", pMsg, pWorker->name, TMSG_INFO(pMsg->msgType));
×
46
  return taosWriteQitem(pWorker->queue, pMsg);
×
47
}
48

49
int32_t qmPutNodeMsgToQueryQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
50
  int32_t code = qndPreprocessQueryMsg(pMgmt->pQnode, pMsg);
×
51
  if (code) return code;
×
52
  return qmPutNodeMsgToWorker(&pMgmt->queryWorker, pMsg);
×
53
}
54

55
int32_t qmPutNodeMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
×
56
  return qmPutNodeMsgToWorker(&pMgmt->fetchWorker, pMsg);
×
57
}
58

59
int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
×
60
  int32_t  code;
61
  SRpcMsg *pMsg;
62

63
  code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
×
64
  if (code) return code;
×
65
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
×
66
  pRpc->pCont = NULL;
×
67

68
  switch (qtype) {
×
69
    case QUERY_QUEUE:
×
70
      dTrace("msg:%p, is created and will put into qnode-query queue, len:%d", pMsg, pRpc->contLen);
×
71
      code = taosWriteQitem(pMgmt->queryWorker.queue, pMsg);
×
72
      return code;
×
73
    case READ_QUEUE:
×
74
    case STATUS_QUEUE:
75
    case FETCH_QUEUE:
76
      dTrace("msg:%p, is created and will put into qnode-fetch queue, len:%d", pMsg, pRpc->contLen);
×
77
      code = taosWriteQitem(pMgmt->fetchWorker.queue, pMsg);
×
78
      return code;
×
79
    default:
×
80
      terrno = TSDB_CODE_INVALID_PARA;
×
81
      rpcFreeCont(pMsg->pCont);
×
82
      taosFreeQitem(pMsg);
×
83
      return terrno;
×
84
  }
85
}
86

87
int32_t qmGetQueueSize(SQnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
×
88
  int32_t size = -1;
×
89

90
  switch (qtype) {
×
91
    case QUERY_QUEUE:
×
92
      size = taosQueueItemSize(pMgmt->queryWorker.queue);
×
93
      break;
×
94
    case FETCH_QUEUE:
×
95
      size = taosQueueItemSize(pMgmt->fetchWorker.queue);
×
96
      break;
×
97
    default:
×
98
      break;
×
99
  }
100

101
  return size;
×
102
}
103

104
int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
×
105
  int32_t code = 0;
×
106

107
  SSingleWorkerCfg queryCfg = {
×
108
      .min = tsNumOfQnodeQueryThreads,
109
      .max = tsNumOfQnodeQueryThreads,
110
      .name = "qnode-query",
111
      .fp = (FItem)qmProcessQueue,
112
      .param = pMgmt,
113
      .poolType = QUERY_AUTO_QWORKER_POOL,
114
  };
115

116
  if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg)) != 0) {
×
117
    dError("failed to start qnode-query worker since %s", tstrerror(code));
×
118
    return code;
×
119
  }
120

121
  tsNumOfQueryThreads += tsNumOfQnodeQueryThreads;
×
122

123
  SSingleWorkerCfg fetchCfg = {
×
124
      .min = tsNumOfQnodeFetchThreads,
125
      .max = tsNumOfQnodeFetchThreads,
126
      .name = "qnode-fetch",
127
      .fp = (FItem)qmProcessQueue,
128
      .param = pMgmt,
129
  };
130

131
  if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg)) != 0) {
×
132
    dError("failed to start qnode-fetch worker since %s", tstrerror(code));
×
133
    return code;
×
134
  }
135

136
  dDebug("qnode workers are initialized");
×
137
  return code;
×
138
}
139

140
void qmStopWorker(SQnodeMgmt *pMgmt) {
×
141
  tSingleWorkerCleanup(&pMgmt->queryWorker);
×
142
  tSingleWorkerCleanup(&pMgmt->fetchWorker);
×
143
  dDebug("qnode workers are closed");
×
144
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc