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

taosdata / TDengine / #3533

20 Nov 2024 07:11AM UTC coverage: 58.848% (-1.9%) from 60.78%
#3533

push

travis-ci

web-flow
Merge pull request #28823 from taosdata/fix/3.0/TD-32587

fix:[TD-32587]fix stmt segmentation fault

115578 of 252434 branches covered (45.79%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 1 file covered. (25.0%)

8038 existing lines in 233 files now uncovered.

194926 of 275199 relevant lines covered (70.83%)

1494459.59 hits per line

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

51.72
/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) {
180,774✔
30
  SQnodeMgmt *pMgmt = pInfo->ahandle;
180,774✔
31
  dTrace("msg:%p, get from qnode queue", pMsg);
180,774✔
32

33
  int32_t code = qndProcessQueryMsg(pMgmt->pQnode, pInfo, pMsg);
180,774✔
34
  if (IsReq(pMsg) && code != TSDB_CODE_ACTION_IN_PROGRESS) {
180,778!
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);
180,778✔
40
  rpcFreeCont(pMsg->pCont);
180,778✔
41
  taosFreeQitem(pMsg);
180,778✔
42
}
180,778✔
43

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

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

55
int32_t qmPutNodeMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
132,663✔
56
  return qmPutNodeMsgToWorker(&pMgmt->fetchWorker, pMsg);
132,663✔
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) {
18,564✔
87
  int32_t size = -1;
18,564✔
88

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

100
  return size;
18,564✔
101
}
102

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

106
  SSingleWorkerCfg queryCfg = {
277✔
107
      .min = tsNumOfVnodeQueryThreads,
108
      .max = tsNumOfVnodeQueryThreads,
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) {
277!
116
    dError("failed to start qnode-query worker since %s", tstrerror(code));
×
117
    return code;
×
118
  }
119

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

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

133
  dDebug("qnode workers are initialized");
277✔
134
  return code;
277✔
135
}
136

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