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

taosdata / TDengine / #4513

17 Jul 2025 02:02AM UTC coverage: 31.359% (-31.1%) from 62.446%
#4513

push

travis-ci

web-flow
Merge pull request #31914 from taosdata/fix/3.0/compare-ans-failed

fix:Convert line endings from LF to CRLF for ans file

68541 of 301034 branches covered (22.77%)

Branch coverage included in aggregate %.

117356 of 291771 relevant lines covered (40.22%)

602262.98 hits per line

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

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

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

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

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

40
  mTrace("msg:%p, in query queue is processing", pMsg);
12!
41
  switch (pMsg->msgType) {
12!
42
    case TDMT_SCH_QUERY:
3✔
43
    case TDMT_SCH_MERGE_QUERY:
44
      code = qWorkerProcessQueryMsg(&handle, pMnode->pQuery, pMsg, 0);
3✔
45
      break;
3✔
46
    case TDMT_SCH_QUERY_CONTINUE:
×
47
      code = qWorkerProcessCQueryMsg(&handle, pMnode->pQuery, pMsg, 0);
×
48
      break;
×
49
    case TDMT_SCH_FETCH:
3✔
50
    case TDMT_SCH_MERGE_FETCH:
51
      code = qWorkerProcessFetchMsg(pMnode, pMnode->pQuery, pMsg, 0);
3✔
52
      break;
3✔
53
    case TDMT_SCH_DROP_TASK:
3✔
54
      code = qWorkerProcessDropMsg(pMnode, pMnode->pQuery, pMsg, 0);
3✔
55
      break;
3✔
56
    case TDMT_SCH_QUERY_HEARTBEAT:
3✔
57
      code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg, 0);
3✔
58
      break;
3✔
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;
12!
68
  return code;
12✔
69
}
70

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

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

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

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

97
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
22✔
98
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
22!
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));
22✔
105
  if (NULL == batchRsp.pRsps) {
22!
106
    code = terrno;
×
107
    goto _exit;
×
108
  }
109

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

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

119
    MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(req->msgType)];
58✔
120
    if (fp == NULL) {
58!
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)) {
58✔
128
      rsp.rspCode = terrno;
9✔
129
    } else {
130
      rsp.rspCode = 0;
49✔
131
    }
132
    rsp.msgIdx = req->msgIdx;
58✔
133
    rsp.reqType = reqMsg.msgType;
58✔
134
    rsp.msgLen = reqMsg.info.rspLen;
58✔
135
    rsp.msg = reqMsg.info.rsp;
58✔
136

137
    if (taosArrayPush(batchRsp.pRsps, &rsp) == NULL) {
116!
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);
22✔
144
  if (rspSize < 0) {
22!
145
    code = TSDB_CODE_OUT_OF_MEMORY;
×
146
    goto _exit;
×
147
  }
148
  pRsp = rpcMallocCont(rspSize);
22✔
149
  if (pRsp == NULL) {
22!
150
    code = terrno;
×
151
    goto _exit;
×
152
  }
153
  if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
22!
154
    code = TSDB_CODE_OUT_OF_MEMORY;
×
155
    goto _exit;
×
156
  }
157

158
_exit:
22✔
159

160
  pMsg->info.rsp = pRsp;
22✔
161
  pMsg->info.rspLen = rspSize;
22✔
162

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

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

170
  TAOS_RETURN(code);
22✔
171
}
172

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

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

189
  return 0;
15✔
190
}
191

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