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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

web-flow
Merge pull request #29874 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 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

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

UNCOV
27
void mndPostProcessQueryMsg(SRpcMsg *pMsg) {
×
UNCOV
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

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

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

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

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

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

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

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

UNCOV
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

UNCOV
96
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
×
UNCOV
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

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

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

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

UNCOV
118
    MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(req->msgType)];
×
UNCOV
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

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

UNCOV
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

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

UNCOV
157
_exit:
×
158

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

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

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

UNCOV
169
  TAOS_RETURN(code);
×
170
}
171

UNCOV
172
int32_t mndInitQuery(SMnode *pMnode) {
×
UNCOV
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

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

UNCOV
188
  return 0;
×
189
}
190

UNCOV
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