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

taosdata / TDengine / #4548

22 Jul 2025 02:37AM UTC coverage: 54.273% (-3.0%) from 57.287%
#4548

push

travis-ci

GitHub
Merge pull request #32061 from taosdata/new_testcases

132738 of 315239 branches covered (42.11%)

Branch coverage included in aggregate %.

201371 of 300373 relevant lines covered (67.04%)

3475977.14 hits per line

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

61.62
/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) {
14,136✔
22
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return 0;
14,136!
23
  SMnode *pMnode = pMsg->info.node;
14,136✔
24
  return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg, false);
14,136✔
25
}
26

27
void mndPostProcessQueryMsg(SRpcMsg *pMsg) {
4,468✔
28
  if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return;
4,468!
29
  SMnode *pMnode = pMsg->info.node;
×
30
  (void)qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg);
×
31
}
32

33
int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo *pInfo) {
50,868✔
34
  int32_t code = -1;
50,868✔
35
  SMnode *pMnode = pMsg->info.node;
50,868✔
36

37
  SReadHandle handle = {0};
50,868✔
38
  handle =  (SReadHandle){.mnd = pMnode, .pMsgCb = &pMnode->msgCb, .pWorkerCb = pInfo->workerCb};
50,868✔
39

40
  mTrace("msg:%p, in query queue is processing", pMsg);
50,868!
41
  switch (pMsg->msgType) {
50,868!
42
    case TDMT_SCH_QUERY:
14,136✔
43
    case TDMT_SCH_MERGE_QUERY:
44
      code = qWorkerProcessQueryMsg(&handle, pMnode->pQuery, pMsg, 0);
14,136✔
45
      break;
14,136✔
46
    case TDMT_SCH_QUERY_CONTINUE:
×
47
      code = qWorkerProcessCQueryMsg(&handle, pMnode->pQuery, pMsg, 0);
×
48
      break;
×
49
    case TDMT_SCH_FETCH:
14,029✔
50
    case TDMT_SCH_MERGE_FETCH:
51
      code = qWorkerProcessFetchMsg(pMnode, pMnode->pQuery, pMsg, 0);
14,029✔
52
      break;
14,029✔
53
    case TDMT_SCH_DROP_TASK:
14,111✔
54
      code = qWorkerProcessDropMsg(pMnode, pMnode->pQuery, pMsg, 0);
14,111✔
55
      break;
14,111✔
56
    case TDMT_SCH_QUERY_HEARTBEAT:
8,592✔
57
      code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg, 0);
8,592✔
58
      break;
8,592✔
59
    case TDMT_SCH_TASK_NOTIFY:
×
60
      code = qWorkerProcessNotifyMsg(pMnode, pMnode->pQuery, pMsg, 0);
×
61
      break;
×
62
    default:
×
63
      terrno = TSDB_CODE_APP_ERROR;
×
64
      mError("unknown msg type:%d in query queue", pMsg->msgType);
×
65
  }
66

67
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
50,868!
68
  return code;
50,868✔
69
}
70

71
static FORCE_INLINE void mnodeFreeSBatchRspMsg(void *p) {
101,476✔
72
  if (NULL == p) {
101,476!
73
    return;
×
74
  }
75

76
  SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
101,476✔
77
  rpcFreeCont(pRsp->msg);
101,476✔
78
}
79

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

91
  if ((code = tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) != 0) {
40,937!
92
    code = TSDB_CODE_OUT_OF_MEMORY;
×
93
    mError("tDeserializeSBatchReq failed");
×
94
    goto _exit;
×
95
  }
96

97
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
40,938✔
98
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
40,936!
99
    code = TSDB_CODE_INVALID_MSG;
×
100
    mError("too many msgs %d in mnode batch meta req", msgNum);
×
101
    goto _exit;
×
102
  }
103

104
  batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
40,936✔
105
  if (NULL == batchRsp.pRsps) {
40,938!
106
    code = terrno;
×
107
    goto _exit;
×
108
  }
109

110
  for (int32_t i = 0; i < msgNum; ++i) {
142,415✔
111
    SBatchMsg *req = taosArrayGet(batchReq.pMsgs, i);
101,475✔
112

113
    reqMsg.msgType = req->msgType;
101,475✔
114
    reqMsg.pCont = req->msg;
101,475✔
115
    reqMsg.contLen = req->msgLen;
101,475✔
116
    reqMsg.info.rsp = NULL;
101,475✔
117
    reqMsg.info.rspLen = 0;
101,475✔
118

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

127
    if ((*fp)(&reqMsg)) {
101,475✔
128
      rsp.rspCode = terrno;
21,029✔
129
    } else {
130
      rsp.rspCode = 0;
80,446✔
131
    }
132
    rsp.msgIdx = req->msgIdx;
101,477✔
133
    rsp.reqType = reqMsg.msgType;
101,477✔
134
    rsp.msgLen = reqMsg.info.rspLen;
101,477✔
135
    rsp.msg = reqMsg.info.rsp;
101,477✔
136

137
    if (taosArrayPush(batchRsp.pRsps, &rsp) == NULL) {
202,954!
138
      mError("msg:%p, failed to put array since %s, app:%p type:%s", pMsg, terrstr(), pMsg->info.ahandle,
×
139
             TMSG_INFO(pMsg->msgType));
140
    }
141
  }
142

143
  rspSize = tSerializeSBatchRsp(NULL, 0, &batchRsp);
40,940✔
144
  if (rspSize < 0) {
40,937!
145
    code = TSDB_CODE_OUT_OF_MEMORY;
×
146
    goto _exit;
×
147
  }
148
  pRsp = rpcMallocCont(rspSize);
40,937✔
149
  if (pRsp == NULL) {
40,936!
150
    code = terrno;
×
151
    goto _exit;
×
152
  }
153
  if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
40,936!
154
    code = TSDB_CODE_OUT_OF_MEMORY;
×
155
    goto _exit;
×
156
  }
157

158
_exit:
40,938✔
159

160
  pMsg->info.rsp = pRsp;
40,938✔
161
  pMsg->info.rspLen = rspSize;
40,938✔
162

163
  if (code) {
40,938!
164
    mError("mnd get batch meta failed cause of %s", tstrerror(code));
×
165
  }
166

167
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
40,938✔
168
  taosArrayDestroyEx(batchRsp.pRsps, mnodeFreeSBatchRspMsg);
40,938✔
169

170
  TAOS_RETURN(code);
40,938✔
171
}
172

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

179
  mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY, mndProcessQueryMsg);
1,906✔
180
  mndSetMsgHandleExt(pMnode, TDMT_SCH_MERGE_QUERY, mndProcessQueryMsg);
1,906✔
181
  mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY_CONTINUE, mndProcessQueryMsg);
1,906✔
182
  mndSetMsgHandleExt(pMnode, TDMT_SCH_FETCH, mndProcessQueryMsg);
1,906✔
183
  mndSetMsgHandleExt(pMnode, TDMT_SCH_MERGE_FETCH, mndProcessQueryMsg);
1,906✔
184
  mndSetMsgHandleExt(pMnode, TDMT_SCH_TASK_NOTIFY, mndProcessQueryMsg);
1,906✔
185
  mndSetMsgHandleExt(pMnode, TDMT_SCH_DROP_TASK, mndProcessQueryMsg);
1,906✔
186
  mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY_HEARTBEAT, mndProcessQueryMsg);
1,906✔
187
  mndSetMsgHandle(pMnode, TDMT_MND_BATCH_META, mndProcessBatchMetaMsg);
1,906✔
188

189
  return 0;
1,906✔
190
}
191

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