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

taosdata / TDengine / #3562

20 Dec 2024 09:57AM UTC coverage: 26.655% (-32.2%) from 58.812%
#3562

push

travis-ci

web-flow
Merge pull request #29229 from taosdata/enh/TS-5749-3.0

enh: seperate tsdb async tasks to different thread pools

21498 of 109421 branches covered (19.65%)

Branch coverage included in aggregate %.

66 of 96 new or added lines in 7 files covered. (68.75%)

39441 existing lines in 157 files now uncovered.

35007 of 102566 relevant lines covered (34.13%)

53922.97 hits per line

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

25.64
/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

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

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

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

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

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

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

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

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

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

86
int32_t qmGetQueueSize(SQnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
1,048✔
87
  int32_t size = -1;
1,048✔
88

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

100
  return size;
1,048✔
101
}
102

103
int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
2✔
104
  int32_t code = 0;
2✔
105

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

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

120
  tsNumOfQueryThreads += tsNumOfQnodeQueryThreads;
2✔
121

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

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

135
  dDebug("qnode workers are initialized");
2!
136
  return code;
2✔
137
}
138

139
void qmStopWorker(SQnodeMgmt *pMgmt) {
2✔
140
  tSingleWorkerCleanup(&pMgmt->queryWorker);
2✔
141
  tSingleWorkerCleanup(&pMgmt->fetchWorker);
2✔
142
  dDebug("qnode workers are closed");
2!
143
}
2✔
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