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

taosdata / TDengine / #3798

31 Mar 2025 10:39AM UTC coverage: 9.424% (-20.9%) from 30.372%
#3798

push

travis-ci

happyguoxy
test:add test cases

21549 of 307601 branches covered (7.01%)

Branch coverage included in aggregate %.

36084 of 303967 relevant lines covered (11.87%)

58620.7 hits per line

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

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

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

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

37
  SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb, .pWorkerCb = pInfo->workerCb};
×
38

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

66
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
×
67
  return code;
×
68
}
69

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

75
  SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
×
76
  rpcFreeCont(pRsp->msg);
×
77
}
78

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

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

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

103
  batchRsp.pRsps = taosArrayInit(msgNum, sizeof(SBatchRspMsg));
×
104
  if (NULL == batchRsp.pRsps) {
×
105
    code = terrno;
×
106
    goto _exit;
×
107
  }
108

109
  for (int32_t i = 0; i < msgNum; ++i) {
×
110
    SBatchMsg *req = taosArrayGet(batchReq.pMsgs, i);
×
111

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

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

126
    if ((*fp)(&reqMsg)) {
×
127
      rsp.rspCode = terrno;
×
128
    } else {
129
      rsp.rspCode = 0;
×
130
    }
131
    rsp.msgIdx = req->msgIdx;
×
132
    rsp.reqType = reqMsg.msgType;
×
133
    rsp.msgLen = reqMsg.info.rspLen;
×
134
    rsp.msg = reqMsg.info.rsp;
×
135

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

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

157
_exit:
×
158

159
  pMsg->info.rsp = pRsp;
×
160
  pMsg->info.rspLen = rspSize;
×
161

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

166
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
×
167
  taosArrayDestroyEx(batchRsp.pRsps, mnodeFreeSBatchRspMsg);
×
168

169
  TAOS_RETURN(code);
×
170
}
171

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

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

188
  return 0;
×
189
}
190

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