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

taosdata / TDengine / #3548

04 Dec 2024 01:03PM UTC coverage: 59.846% (-0.8%) from 60.691%
#3548

push

travis-ci

web-flow
Merge pull request #29033 from taosdata/fix/calculate-vnode-memory-used

fix/calculate-vnode-memory-used

118484 of 254183 branches covered (46.61%)

Branch coverage included in aggregate %.

199691 of 277471 relevant lines covered (71.97%)

18794141.86 hits per line

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

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

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

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

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

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

70
static FORCE_INLINE void mnodeFreeSBatchRspMsg(void *p) {
5,495,326✔
71
  if (NULL == p) {
5,495,326!
72
    return;
×
73
  }
74

75
  SBatchRspMsg *pRsp = (SBatchRspMsg *)p;
5,495,326✔
76
  rpcFreeCont(pRsp->msg);
5,495,326✔
77
}
78

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

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

96
  int32_t msgNum = taosArrayGetSize(batchReq.pMsgs);
1,780,595✔
97
  if (msgNum >= MAX_META_MSG_IN_BATCH) {
1,780,580!
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));
1,780,580✔
104
  if (NULL == batchRsp.pRsps) {
1,780,576!
105
    code = terrno;
×
106
    goto _exit;
×
107
  }
108

109
  for (int32_t i = 0; i < msgNum; ++i) {
7,275,749✔
110
    SBatchMsg *req = taosArrayGet(batchReq.pMsgs, i);
5,495,220✔
111

112
    reqMsg.msgType = req->msgType;
5,495,088✔
113
    reqMsg.pCont = req->msg;
5,495,088✔
114
    reqMsg.contLen = req->msgLen;
5,495,088✔
115
    reqMsg.info.rsp = NULL;
5,495,088✔
116
    reqMsg.info.rspLen = 0;
5,495,088✔
117

118
    MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(req->msgType)];
5,495,088✔
119
    if (fp == NULL) {
5,495,088!
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)) {
5,495,088✔
127
      rsp.rspCode = terrno;
1,490,549✔
128
    } else {
129
      rsp.rspCode = 0;
4,004,786✔
130
    }
131
    rsp.msgIdx = req->msgIdx;
5,495,355✔
132
    rsp.reqType = reqMsg.msgType;
5,495,355✔
133
    rsp.msgLen = reqMsg.info.rspLen;
5,495,355✔
134
    rsp.msg = reqMsg.info.rsp;
5,495,355✔
135

136
    if (taosArrayPush(batchRsp.pRsps, &rsp) == NULL) {
10,990,539!
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);
1,780,529✔
143
  if (rspSize < 0) {
1,780,586!
144
    code = TSDB_CODE_OUT_OF_MEMORY;
×
145
    goto _exit;
×
146
  }
147
  pRsp = rpcMallocCont(rspSize);
1,780,586✔
148
  if (pRsp == NULL) {
1,780,528!
149
    code = terrno;
×
150
    goto _exit;
×
151
  }
152
  if (tSerializeSBatchRsp(pRsp, rspSize, &batchRsp) < 0) {
1,780,528!
153
    code = TSDB_CODE_OUT_OF_MEMORY;
×
154
    goto _exit;
×
155
  }
156

157
_exit:
1,780,603✔
158

159
  pMsg->info.rsp = pRsp;
1,780,603✔
160
  pMsg->info.rspLen = rspSize;
1,780,603✔
161

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

166
  taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
1,780,603✔
167
  taosArrayDestroyEx(batchRsp.pRsps, mnodeFreeSBatchRspMsg);
1,780,590✔
168

169
  TAOS_RETURN(code);
1,780,592✔
170
}
171

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

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

188
  return 0;
1,701✔
189
}
190

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

© 2025 Coveralls, Inc