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

taosdata / TDengine / #4768

01 Oct 2025 04:06AM UTC coverage: 57.85% (-0.8%) from 58.606%
#4768

push

travis-ci

web-flow
Merge pull request #33171 from taosdata/merge/3.3.6tomain

merge: from 3.3.6 to main branch

137167 of 302743 branches covered (45.31%)

Branch coverage included in aggregate %.

15 of 20 new or added lines in 2 files covered. (75.0%)

12125 existing lines in 175 files now uncovered.

208282 of 294403 relevant lines covered (70.75%)

5618137.93 hits per line

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

63.98
/source/dnode/mnode/impl/src/mndQuery.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
#include "mndQuery.h"
17
#include "executor.h"
18
#include "mndMnode.h"
19
#include "qworker.h"
20

21
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg, int32_t* qType) {
19,283✔
22
  SMnode *pMnode = pMsg->info.node;
19,283✔
23
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) {
19,283!
UNCOV
24
    return 0;
×
25
  }
26

27
  return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg, false, qType);
19,283✔
28
}
29

30
void mndPostProcessQueryMsg(SRpcMsg *pMsg) {
16,842✔
31
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return;
16,842!
UNCOV
32
  SMnode *pMnode = pMsg->info.node;
×
UNCOV
33
  (void)qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg);
×
34
}
35

36
int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo *pInfo) {
71,309✔
37
  int32_t code = -1;
71,309✔
38
  SMnode *pMnode = pMsg->info.node;
71,309✔
39

40
  SReadHandle handle = {0};
71,309✔
41
  handle =  (SReadHandle){.mnd = pMnode, .pMsgCb = &pMnode->msgCb, .pWorkerCb = pInfo->workerCb};
71,309✔
42

43
  mTrace("msg:%p, in query queue is processing", pMsg);
71,309✔
44
  switch (pMsg->msgType) {
71,309!
45
    case TDMT_SCH_QUERY:
19,283✔
46
    case TDMT_SCH_MERGE_QUERY:
47
      code = qWorkerProcessQueryMsg(&handle, pMnode->pQuery, pMsg, 0);
19,283✔
48
      break;
19,283✔
49
    case TDMT_SCH_QUERY_CONTINUE:
2✔
50
      code = qWorkerProcessCQueryMsg(&handle, pMnode->pQuery, pMsg, 0);
2✔
51
      break;
2✔
52
    case TDMT_SCH_FETCH:
19,231✔
53
    case TDMT_SCH_MERGE_FETCH:
54
      code = qWorkerProcessFetchMsg(pMnode, pMnode->pQuery, pMsg, 0);
19,231✔
55
      break;
19,231✔
56
    case TDMT_SCH_DROP_TASK:
19,169✔
57
      code = qWorkerProcessDropMsg(pMnode, pMnode->pQuery, pMsg, 0);
19,169✔
58
      break;
19,169✔
59
    case TDMT_SCH_QUERY_HEARTBEAT:
13,624✔
60
      code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg, 0);
13,624✔
61
      break;
13,624✔
62
    case TDMT_SCH_TASK_NOTIFY:
×
63
      code = qWorkerProcessNotifyMsg(pMnode, pMnode->pQuery, pMsg, 0);
×
64
      break;
×
UNCOV
65
    default:
×
UNCOV
66
      terrno = TSDB_CODE_APP_ERROR;
×
UNCOV
67
      mError("unknown msg type:%d in query queue", pMsg->msgType);
×
68
  }
69

70
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
71,309!
71
  return code;
71,309✔
72
}
73

74
static FORCE_INLINE void mnodeFreeSBatchRspMsg(void *p) {
216,407✔
75
  if (NULL == p) {
216,407!
UNCOV
76
    return;
×
77
  }
78

79
  SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
216,407✔
80
  rpcFreeCont(pRsp->msg);
216,407✔
81
}
82

83
int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
110,541✔
84
  int32_t      code = 0;
110,541✔
85
  int32_t      rspSize = 0;
110,541✔
86
  SBatchReq    batchReq = {0};
110,541✔
87
  SBatchMsg    req = {0};
110,541✔
88
  SBatchRspMsg rsp = {0};
110,541✔
89
  SBatchRsp    batchRsp = {0};
110,541✔
90
  SRpcMsg      reqMsg = *pMsg;
110,541✔
91
  void        *pRsp = NULL;
110,541✔
92
  SMnode      *pMnode = pMsg->info.node;
110,541✔
93

94
  if ((code = tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) != 0) {
110,541!
UNCOV
95
    code = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
96
    mError("tDeserializeSBatchReq failed");
×
UNCOV
97
    goto _exit;
×
98
  }
99

100
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
110,542✔
101
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
110,541!
UNCOV
102
    code = TSDB_CODE_INVALID_MSG;
×
UNCOV
103
    mError("too many msgs %d in mnode batch meta req", msgNum);
×
UNCOV
104
    goto _exit;
×
105
  }
106

107
  batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
110,541✔
108
  if (NULL == batchRsp.pRsps) {
110,542!
UNCOV
109
    code = terrno;
×
UNCOV
110
    goto _exit;
×
111
  }
112

113
  for (int32_t i = 0; i < msgNum; ++i) {
326,950✔
114
    SBatchMsg *req = taosArrayGet(batchReq.pMsgs, i);
216,408✔
115

116
    reqMsg.msgType = req->msgType;
216,408✔
117
    reqMsg.pCont = req->msg;
216,408✔
118
    reqMsg.contLen = req->msgLen;
216,408✔
119
    reqMsg.info.rsp = NULL;
216,408✔
120
    reqMsg.info.rspLen = 0;
216,408✔
121

122
    MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(req->msgType)];
216,408✔
123
    if (fp == NULL) {
216,408!
124
      mError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
×
UNCOV
125
      code = TSDB_CODE_MSG_NOT_PROCESSED;
×
UNCOV
126
      taosArrayDestroy(batchRsp.pRsps);
×
UNCOV
127
      return -1;
×
128
    }
129

130
    if ((*fp)(&reqMsg)) {
216,408✔
131
      rsp.rspCode = terrno;
56,862✔
132
    } else {
133
      rsp.rspCode = 0;
159,546✔
134
    }
135
    rsp.msgIdx = req->msgIdx;
216,408✔
136
    rsp.reqType = reqMsg.msgType;
216,408✔
137
    rsp.msgLen = reqMsg.info.rspLen;
216,408✔
138
    rsp.msg = reqMsg.info.rsp;
216,408✔
139

140
    if (taosArrayPush(batchRsp.pRsps, &rsp) == NULL) {
432,816!
UNCOV
141
      mError("msg:%p, failed to put array since %s, app:%p type:%s", pMsg, terrstr(), pMsg->info.ahandle,
×
142
             TMSG_INFO(pMsg->msgType));
143
    }
144
  }
145

146
  rspSize = tSerializeSBatchRsp(NULL, 0, &batchRsp);
110,542✔
147
  if (rspSize < 0) {
110,542!
UNCOV
148
    code = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
149
    goto _exit;
×
150
  }
151
  pRsp = rpcMallocCont(rspSize);
110,542✔
152
  if (pRsp == NULL) {
110,542!
UNCOV
153
    code = terrno;
×
154
    goto _exit;
×
155
  }
156
  if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
110,542!
UNCOV
157
    code = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
158
    goto _exit;
×
159
  }
160

161
_exit:
110,541✔
162

163
  pMsg->info.rsp = pRsp;
110,541✔
164
  pMsg->info.rspLen = rspSize;
110,541✔
165

166
  if (code) {
110,541!
UNCOV
167
    mError("mnd get batch meta failed cause of %s", tstrerror(code));
×
168
  }
169

170
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
110,541✔
171
  taosArrayDestroyEx(batchRsp.pRsps, mnodeFreeSBatchRspMsg);
110,541✔
172

173
  TAOS_RETURN(code);
110,542✔
174
}
175

176
int32_t mndInitQuery(SMnode *pMnode) {
1,948✔
177
  if (qWorkerInit(NODE_TYPE_MNODE, MNODE_HANDLE, (void **)&pMnode->pQuery, &pMnode->msgCb) != 0) {
1,948!
UNCOV
178
    mError("failed to init qworker in mnode since %s", terrstr());
×
UNCOV
179
    return -1;
×
180
  }
181

182
  mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY, mndProcessQueryMsg);
1,948✔
183
  mndSetMsgHandleExt(pMnode, TDMT_SCH_MERGE_QUERY, mndProcessQueryMsg);
1,948✔
184
  mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY_CONTINUE, mndProcessQueryMsg);
1,948✔
185
  mndSetMsgHandleExt(pMnode, TDMT_SCH_FETCH, mndProcessQueryMsg);
1,948✔
186
  mndSetMsgHandleExt(pMnode, TDMT_SCH_MERGE_FETCH, mndProcessQueryMsg);
1,948✔
187
  mndSetMsgHandleExt(pMnode, TDMT_SCH_TASK_NOTIFY, mndProcessQueryMsg);
1,948✔
188
  mndSetMsgHandleExt(pMnode, TDMT_SCH_DROP_TASK, mndProcessQueryMsg);
1,948✔
189
  mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY_HEARTBEAT, mndProcessQueryMsg);
1,948✔
190
  mndSetMsgHandle(pMnode, TDMT_MND_BATCH_META, mndProcessBatchMetaMsg);
1,948✔
191

192
  return 0;
1,948✔
193
}
194

195
void mndCleanupQuery(SMnode *pMnode) { qWorkerDestroy((void **)&pMnode->pQuery); }
1,948✔
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