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

taosdata / TDengine / #4955

09 Feb 2026 01:16AM UTC coverage: 66.884% (+0.008%) from 66.876%
#4955

push

travis-ci

web-flow
docs: add support for recording STMT to CSV files (#34276)

* docs: add support for recording STMT to CSV files

* docs: update version for STMT recording feature in CSV files

205800 of 307696 relevant lines covered (66.88%)

127581826.31 hits per line

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

81.92
/source/dnode/mgmt/mgmt_vnode/src/vmWorker.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
#define _DEFAULT_SOURCE
17
#include "vmInt.h"
18
#include "vnodeInt.h"
19

20
static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) {
8,057,708✔
21
  if (pMsg->info.handle == NULL) return;
8,057,708✔
22
  SRpcMsg rsp = {
16,114,143✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
8,057,934✔
25
      .contLen = pMsg->info.rspLen,
8,056,059✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
8,056,227✔
29
}
30

31
static void vmProcessMultiMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
2,784,843✔
32
  SVnodeMgmt     *pMgmt = pInfo->ahandle;
2,784,843✔
33
  int32_t         code = -1;
2,812,793✔
34
  const STraceId *trace = &pMsg->info.traceId;
2,812,793✔
35

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
2,812,793✔
37
  switch (pMsg->msgType) {
2,812,793✔
38
    case TDMT_DND_CREATE_VNODE:
2,810,642✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
2,810,642✔
40
      break;
2,809,981✔
41
#ifdef USE_MOUNT
42
    case TDMT_DND_RETRIEVE_MOUNT_PATH:
767✔
43
      code = vmProcessRetrieveMountPathReq(pMgmt, pMsg);
767✔
44
      break;
767✔
45
    case TDMT_DND_MOUNT_VNODE:
1,004✔
46
      code = vmProcessMountVnodeReq(pMgmt, pMsg);
1,004✔
47
      break;
1,004✔
48
#endif
49
  }
50

51
  if (IsReq(pMsg)) {
2,811,005✔
52
    if (code != 0) {
2,812,690✔
53
      if (terrno != 0) code = terrno;
516✔
54
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
516✔
55
    }
56
    vmSendRsp(pMsg, code);
2,812,690✔
57
  }
58

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
2,807,773✔
60
  rpcFreeCont(pMsg->pCont);
2,807,773✔
61
  taosFreeQitem(pMsg);
2,808,106✔
62
}
2,810,281✔
63

64
static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
4,265,640✔
65
  SVnodeMgmt     *pMgmt = pInfo->ahandle;
4,265,640✔
66
  int32_t         code = -1;
4,265,640✔
67
  const STraceId *trace = &pMsg->info.traceId;
4,265,640✔
68

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
4,265,640✔
70
  switch (pMsg->msgType) {
4,265,640✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
1,483,359✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
1,483,359✔
76
      break;
1,483,359✔
77
    case TDMT_VND_ALTER_REPLICA:
646,390✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
646,390✔
79
      break;
646,390✔
80
    case TDMT_VND_DISABLE_WRITE:
25,790✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
25,790✔
82
      break;
25,790✔
83
    case TDMT_VND_SET_KEEP_VERSION:
3,264✔
84
      code = vmProcessSetKeepVersionReq(pMgmt, pMsg);
3,264✔
85
      break;
3,264✔
86
    case TDMT_VND_ALTER_HASHRANGE:
25,093✔
87
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
25,093✔
88
      break;
25,093✔
89
    case TDMT_DND_ALTER_VNODE_TYPE:
1,964,330✔
90
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
1,964,330✔
91
      break;
1,964,330✔
92
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
93
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
94
      break;
×
95
    case TDMT_VND_ARB_HEARTBEAT:
93,592✔
96
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
93,592✔
97
      break;
93,592✔
98
    case TDMT_VND_ALTER_ELECTBASELINE:
23,822✔
99
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
23,822✔
100
      break;
23,822✔
101
    default:
×
102
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
103
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
104
  }
105

106
  if (IsReq(pMsg)) {
4,265,640✔
107
    if (code != 0) {
4,265,640✔
108
      if (terrno != 0) code = terrno;
1,871,540✔
109
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
1,871,540✔
110
    }
111
    vmSendRsp(pMsg, code);
4,265,640✔
112
  }
113

114
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
4,265,640✔
115
  rpcFreeCont(pMsg->pCont);
4,265,640✔
116
  taosFreeQitem(pMsg);
4,265,640✔
117
}
4,265,640✔
118

119
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
343,034,686✔
120
  SVnodeObj      *pVnode = pInfo->ahandle;
343,034,686✔
121
  const STraceId *trace = &pMsg->info.traceId;
343,046,056✔
122

123
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
343,052,060✔
124
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
343,052,449✔
125
  if (code != 0) {
342,941,000✔
126
    if (terrno != 0) code = terrno;
290,949✔
127
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
290,949✔
128
    vmSendRsp(pMsg, code);
290,949✔
129
  }
130

131
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
342,941,000✔
132
  rpcFreeCont(pMsg->pCont);
342,942,257✔
133
  taosFreeQitem(pMsg);
342,964,455✔
134
}
342,941,927✔
135

136
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
729,928,145✔
137
  SVnodeObj *pVnode = pInfo->ahandle;
729,928,145✔
138
  SRpcMsg   *pMsg = NULL;
729,942,807✔
139

140
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,476,699,098✔
141
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
746,649,778✔
142
    const STraceId *trace = &pMsg->info.traceId;
746,515,513✔
143
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
746,773,077✔
144

145
    terrno = 0;
746,775,644✔
146
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
746,688,617✔
147
    if (code != 0) {
746,795,648✔
148
      if (code == -1 && terrno != 0) {
689,713✔
149
        code = terrno;
×
150
      }
151

152
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
689,713✔
153
        dGDebug("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
×
154
      } else {
155
        dGError("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
689,713✔
156
      }
157

158
      vmSendRsp(pMsg, code);
689,713✔
159
    }
160

161
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
746,795,648✔
162
    rpcFreeCont(pMsg->pCont);
746,795,648✔
163
    taosFreeQitem(pMsg);
746,768,345✔
164
  }
165
}
730,088,773✔
166

167
static void vmProcessStreamReaderQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
28,729,570✔
168
  SVnodeObj *pVnode = pInfo->ahandle;
28,729,570✔
169
  const STraceId *trace = &pMsg->info.traceId;
28,729,777✔
170
  dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
28,728,824✔
171

172
  terrno = 0;
28,728,824✔
173
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
28,728,777✔
174
  if (code != 0) {
28,717,836✔
175
    if (code == -1 && terrno != 0) {
61,736✔
176
      code = terrno;
×
177
    }
178

179
    if (code == 0) {
61,736✔
180
      dGDebug("vgId:%d, msg:%p, success to stream reader since %s [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, terrstr());
×
181
    } else {
182
      dGError("vgId:%d, msg:%p, failed to stream reader since %s [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, terrstr());
61,736✔
183
    }
184
  }
185

186
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
28,717,836✔
187
  rpcFreeCont(pMsg->pCont);
28,717,836✔
188
  taosFreeQitem(pMsg);
28,720,477✔
189
}
28,719,712✔
190

191
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
267,320,123✔
192
  SVnodeObj *pVnode = pInfo->ahandle;
267,320,123✔
193
  SRpcMsg   *pMsg = NULL;
267,320,979✔
194

195
  for (int32_t i = 0; i < numOfMsgs; ++i) {
559,395,406✔
196
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
292,091,982✔
197
    const STraceId *trace = &pMsg->info.traceId;
292,091,188✔
198
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
292,097,326✔
199

200
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
292,097,326✔
201
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
292,082,264✔
202
    rpcFreeCont(pMsg->pCont);
292,082,264✔
203
    taosFreeQitem(pMsg);
292,034,840✔
204
  }
205
}
267,304,956✔
206

207
static void vmSendResponse(SRpcMsg *pMsg) {
×
208
  if (pMsg->info.handle) {
×
209
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
210
    if (rpcSendResponse(&rsp) != 0) {
×
211
      dError("failed to send response since %s", terrstr());
×
212
    }
213
  }
214
}
×
215

216
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
658,390,010✔
217
  STfs *pTfs = pVnode->pImpl->pTfs;
658,390,010✔
218
  if (pTfs) {
658,411,388✔
219
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
658,411,388✔
220
  } else {
221
    return osDataSpaceSufficient();
×
222
  }
223
}
224

225
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
2,147,483,647✔
226
  *pNode = vmAcquireVnode(pMgt, vgId);
2,147,483,647✔
227
  if (*pNode == NULL) {
2,147,483,647✔
228
    return terrno;
2,874,964✔
229
  }
230
  return 0;
2,147,483,647✔
231
}
232
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
2,147,483,647✔
233
  int32_t         code = 0;
2,147,483,647✔
234
  SMsgHead *      pHead = pMsg->pCont;
2,147,483,647✔
235
  SVnodeObj *     pVnode = NULL;
2,147,483,647✔
236
  const STraceId *trace = &pMsg->info.traceId;
2,147,483,647✔
237

238
  if (pMsg->contLen < sizeof(SMsgHead)) {
2,147,483,647✔
239
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
240
            pMsg->contLen);
241
    return TSDB_CODE_INVALID_MSG;
×
242
  }
243

244
  pHead->contLen = ntohl(pHead->contLen);
2,147,483,647✔
245
  pHead->vgId = ntohl(pHead->vgId);
2,147,483,647✔
246
  
247
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
2,147,483,647✔
248
  if (code != 0) {
2,147,483,647✔
249
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
2,874,964✔
250
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
251
    return code;
2,875,395✔
252
  }
253

254
  switch (qtype) {
2,147,483,647✔
255
    case QUERY_QUEUE:
342,906,566✔
256
      // let's put into different query processing queue. The query type is extracted during preprocessing procedure,
257
      // mquery-queue for meta info query, and query-queue for ordinary users' queries.
258
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
342,906,566✔
259
      if (code) {
342,917,069✔
260
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
261
      } else {
262
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
342,917,069✔
263
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
342,917,069✔
264
      }
265
      break;
342,984,916✔
266
    case FETCH_QUEUE:
746,381,553✔
267
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
746,381,553✔
268
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
746,381,553✔
269
      break;
746,782,933✔
270
    case WRITE_QUEUE:
658,378,156✔
271
      if (!vmDataSpaceSufficient(pVnode)) {
658,378,156✔
272
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
273
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
274
               tstrerror(code), TMSG_INFO(pMsg->msgType));
275
        break;
×
276
      }
277
#if 0
278
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
279
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
280
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
281
               tstrerror(code), TMSG_INFO(pMsg->msgType));
282
        break;
283
      }
284
#endif
285
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
658,385,513✔
286
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
141,851✔
287
               TMSG_INFO(pMsg->msgType));
288
        code = TSDB_CODE_VND_STOPPED;
141,851✔
289
        break;
141,851✔
290
      }
291
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
658,222,394✔
292
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
658,223,383✔
293
      break;
658,271,677✔
294
    case SYNC_QUEUE:
253,371,189✔
295
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
253,371,189✔
296
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
253,371,189✔
297
      break;
253,384,837✔
298
    case SYNC_RD_QUEUE:
38,697,253✔
299
      if(tsSyncLogHeartbeat){
38,697,253✔
300
        dGInfo("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
×
301
      }
302
      else{
303
        dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
38,697,253✔
304
      }
305
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
38,697,253✔
306
      break;
38,710,777✔
307
    case APPLY_QUEUE:
176,594,838✔
308
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
176,594,838✔
309
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
176,594,838✔
310
      break;
176,600,430✔
311
    case STREAM_READER_QUEUE:
28,709,858✔
312
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
28,709,858✔
313
              TMSG_INFO(pMsg->msgType));
314
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
28,711,318✔
315
      break;
28,726,449✔
316
    default:
×
317
      code = TSDB_CODE_INVALID_MSG;
×
318
      break;
×
319
  }
320

321
  vmReleaseVnode(pMgmt, pVnode);
2,147,483,647✔
322
  return code;
2,147,483,647✔
323
}
324

325
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
38,877,520✔
326

327
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
177,120,498✔
328

329
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
657,425,358✔
330

331
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
283,060,475✔
332

333
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
746,723,464✔
334

335
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
28,739,617✔
336

337
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
2,794,042✔
338
  const STraceId *trace = &pMsg->info.traceId;
2,794,042✔
339
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
2,812,793✔
340
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
2,812,793✔
341
}
342

343
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
4,265,640✔
344
  const STraceId *trace = &pMsg->info.traceId;
4,265,640✔
345
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
4,265,640✔
346
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
4,265,640✔
347
}
348

349
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
316,341,791✔
350
  int32_t code;
351
  if (pRpc->contLen < sizeof(SMsgHead)) {
316,341,791✔
352
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
353
           pRpc->contLen);
354
    rpcFreeCont(pRpc->pCont);
×
355
    pRpc->pCont = NULL;
×
356
    return TSDB_CODE_INVALID_MSG;
×
357
  }
358

359
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
316,342,429✔
360
  SRpcMsg *pMsg;
316,340,379✔
361
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
316,345,378✔
362
  if (code) {
316,338,295✔
363
    rpcFreeCont(pRpc->pCont);
×
364
    pRpc->pCont = NULL;
×
365
    return code;
×
366
  }
367

368
  SMsgHead *pHead = pRpc->pCont;
316,338,295✔
369
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
316,343,233✔
370

371
  pHead->contLen = htonl(pHead->contLen);
316,343,233✔
372
  pHead->vgId = htonl(pHead->vgId);
316,339,579✔
373
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
316,336,985✔
374
  pRpc->pCont = NULL;
316,336,985✔
375

376
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
316,349,180✔
377
  if (code != 0) {
316,360,745✔
378
    dTrace("msg:%p, is freed", pMsg);
1,335,041✔
379
    rpcFreeCont(pMsg->pCont);
1,335,041✔
380
    taosFreeQitem(pMsg);
1,334,936✔
381
  }
382

383
  return code;
316,352,542✔
384
}
385

386
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
16,975,569✔
387
  int32_t    size = -1;
16,975,569✔
388
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
16,975,569✔
389
  if (pVnode != NULL) {
16,992,361✔
390
    switch (qtype) {
9,266,390✔
391
      case WRITE_QUEUE:
×
392
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
393
        break;
×
394
      case SYNC_QUEUE:
×
395
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
396
        break;
×
397
      case APPLY_QUEUE:
9,266,390✔
398
        size = taosQueueItemSize(pVnode->pApplyW.queue);
9,266,390✔
399
        break;
9,270,870✔
400
      case QUERY_QUEUE:
×
401
        size = taosQueueItemSize(pVnode->pQueryQ);
×
402
        break;
×
403
      case FETCH_QUEUE:
×
404
        size = taosQueueItemSize(pVnode->pFetchQ);
×
405
        break;
×
406
      case STREAM_READER_QUEUE:
×
407
        size = taosQueueItemSize(pVnode->pStreamReaderQ);
×
408
        break;
×
409
      default:
×
410
        break;
×
411
    }
412
  }
413
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
16,996,841✔
414
  if (size < 0) {
16,983,987✔
415
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
7,704,848✔
416
    size = 0;
7,702,587✔
417
  }
418
  return size;
16,981,726✔
419
}
420

421
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
3,857,652✔
422
  int32_t         code = 0;
3,857,652✔
423
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
3,857,652✔
424
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
3,855,684✔
425
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
3,858,435✔
426
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
3,857,205✔
427
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
3,856,046✔
428
  if (code) {
3,859,114✔
429
    return code;
×
430
  }
431
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
3,859,114✔
432
  if (code) {
3,859,193✔
433
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
434
    return code;
×
435
  }
436
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
3,859,193✔
437
  if (code) {
3,859,290✔
438
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
439
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
440
    return code;
×
441
  }
442
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
3,859,290✔
443
  if (code) {
3,859,290✔
444
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
445
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
446
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
447
    return code;
×
448
  }
449

450
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
3,859,290✔
451
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
3,859,290✔
452
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
3,859,290✔
453

454
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
3,859,290✔
455
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
3,859,290✔
456
    return TSDB_CODE_OUT_OF_MEMORY;
×
457
  }
458

459
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
3,859,290✔
460
        taosQueueGetThreadId(pVnode->pWriteW.queue));
461
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
3,859,290✔
462
        taosQueueGetThreadId(pVnode->pSyncW.queue));
463
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
3,859,290✔
464
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
465
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
3,859,290✔
466
        taosQueueGetThreadId(pVnode->pApplyW.queue));
467
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
3,859,290✔
468
  dInfo("vgId:%d, stream-reader-queue:%p is alloced", pVnode->vgId, pVnode->pStreamReaderQ);
3,859,290✔
469
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
3,859,290✔
470
        taosQueueGetThreadId(pVnode->pFetchQ));
471
  return 0;
3,859,290✔
472
}
473

474
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
3,859,088✔
475
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
3,859,088✔
476
  tQueryAutoQWorkerFreeQueue(&pMgmt->streamReaderPool, pVnode->pStreamReaderQ);
3,859,290✔
477
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
3,859,290✔
478

479
  pVnode->pQueryQ = NULL;
3,859,290✔
480
  pVnode->pFetchQ = NULL;
3,859,290✔
481
  pVnode->pStreamReaderQ = NULL;
3,858,594✔
482
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
3,859,290✔
483
}
3,859,290✔
484

485
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
566,830✔
486
  int32_t code = 0;
566,830✔
487

488
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
566,830✔
489
  pQPool->name = "vnode-query";
566,830✔
490
  pQPool->min = tsNumOfVnodeQueryThreads;
566,830✔
491
  pQPool->max = tsNumOfVnodeQueryThreads;
566,830✔
492
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
566,830✔
493

494
  SQueryAutoQWorkerPool *pSPool = &pMgmt->streamReaderPool;
566,830✔
495
  pSPool->name = "vnode-st-reader";
566,830✔
496
  pSPool->min = tsNumOfVnodeStreamReaderThreads;
566,830✔
497
  pSPool->max = tsNumOfVnodeStreamReaderThreads;
566,830✔
498
  if ((code = tQueryAutoQWorkerInit(pSPool)) != 0) return code;
566,830✔
499

500
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
566,830✔
501

502
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
566,830✔
503
  pFPool->name = "vnode-fetch";
566,830✔
504
  pFPool->max = tsNumOfVnodeFetchThreads;
566,830✔
505
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
566,830✔
506

507
  SSingleWorkerCfg mgmtCfg = {
566,830✔
508
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
509

510
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
566,830✔
511

512
  int32_t threadNum = 0;
566,830✔
513
  if (tsNumOfCores == 1) {
566,830✔
514
    threadNum = 2;
×
515
  } else {
516
    threadNum = tsNumOfCores;
566,830✔
517
  }
518
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
566,830✔
519
                                   .max = threadNum,
520
                                   .name = "vnode-multi-mgmt",
521
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
522
                                   .param = pMgmt};
523

524
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
566,830✔
525
  dDebug("vnode workers are initialized");
566,830✔
526
  return 0;
566,830✔
527
}
528

529
void vmStopWorker(SVnodeMgmt *pMgmt) {
566,830✔
530
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
566,830✔
531
  tWWorkerCleanup(&pMgmt->fetchPool);
566,830✔
532
  tQueryAutoQWorkerCleanup(&pMgmt->streamReaderPool);
566,830✔
533
  dDebug("vnode workers are closed");
566,830✔
534
}
566,830✔
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