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

taosdata / TDengine / #4703

01 Sep 2025 11:36AM UTC coverage: 58.16% (-0.9%) from 59.056%
#4703

push

travis-ci

web-flow
Merge pull request #32834 from taosdata/docs/wangxu/simplify-get-started

refactor: simplify get started

133101 of 291897 branches covered (45.6%)

Branch coverage included in aggregate %.

201587 of 283568 relevant lines covered (71.09%)

5506801.45 hits per line

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

65.74
/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) {
21,852✔
21
  if (pMsg->info.handle == NULL) return;
21,852!
22
  SRpcMsg rsp = {
21,852✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
21,852✔
25
      .contLen = pMsg->info.rspLen,
21,852✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
21,852✔
29
}
30

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
9,756!
37
  switch (pMsg->msgType) {
9,756!
38
    case TDMT_DND_CREATE_VNODE:
9,742✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
9,742✔
40
      break;
9,742✔
41
#ifdef USE_MOUNT
42
    case TDMT_DND_RETRIEVE_MOUNT_PATH:
6✔
43
      code = vmProcessRetrieveMountPathReq(pMgmt, pMsg);
6✔
44
      break;
6✔
45
    case TDMT_DND_MOUNT_VNODE:
8✔
46
      code = vmProcessMountVnodeReq(pMgmt, pMsg);
8✔
47
      break;
8✔
48
#endif
49
  }
50

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
9,755!
60
  rpcFreeCont(pMsg->pCont);
9,755✔
61
  taosFreeQitem(pMsg);
9,755✔
62
}
9,756✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
8,942!
70
  switch (pMsg->msgType) {
8,942!
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
4,019✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
4,019✔
76
      break;
4,019✔
77
    case TDMT_VND_ALTER_REPLICA:
1,196✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
1,196✔
79
      break;
1,196✔
80
    case TDMT_VND_DISABLE_WRITE:
62✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
62✔
82
      break;
62✔
83
    case TDMT_VND_ALTER_HASHRANGE:
62✔
84
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
62✔
85
      break;
62✔
86
    case TDMT_DND_ALTER_VNODE_TYPE:
3,476✔
87
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
3,476✔
88
      break;
3,476✔
89
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
90
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
91
      break;
×
92
    case TDMT_VND_ARB_HEARTBEAT:
127✔
93
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
127✔
94
      break;
127✔
95
    default:
×
96
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
97
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
98
  }
99

100
  if (IsReq(pMsg)) {
8,942!
101
    if (code != 0) {
8,942✔
102
      if (terrno != 0) code = terrno;
3,297!
103
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
3,297!
104
    }
105
    vmSendRsp(pMsg, code);
8,942✔
106
  }
107

108
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
8,942!
109
  rpcFreeCont(pMsg->pCont);
8,942✔
110
  taosFreeQitem(pMsg);
8,942✔
111
}
8,942✔
112

113
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
1,350,135✔
114
  SVnodeObj      *pVnode = pInfo->ahandle;
1,350,135✔
115
  const STraceId *trace = &pMsg->info.traceId;
1,350,135✔
116

117
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
1,350,135!
118
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
1,350,135✔
119
  if (code != 0) {
1,350,080✔
120
    if (terrno != 0) code = terrno;
1,206!
121
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
1,206!
122
    vmSendRsp(pMsg, code);
1,206✔
123
  }
124

125
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,350,080!
126
  rpcFreeCont(pMsg->pCont);
1,350,080✔
127
  taosFreeQitem(pMsg);
1,350,128✔
128
}
1,350,132✔
129

130
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
3,467,640✔
131
  SVnodeObj *pVnode = pInfo->ahandle;
3,467,640✔
132
  SRpcMsg   *pMsg = NULL;
3,467,640✔
133

134
  for (int32_t i = 0; i < numOfMsgs; ++i) {
6,968,795✔
135
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
3,500,048!
136
    const STraceId *trace = &pMsg->info.traceId;
3,500,842✔
137
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
3,500,842!
138

139
    terrno = 0;
3,500,843✔
140
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
3,499,929✔
141
    if (code != 0) {
3,500,962✔
142
      if (code == -1 && terrno != 0) {
1,948!
143
        code = terrno;
×
144
      }
145

146
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
1,948!
147
        dGDebug("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
×
148
      } else {
149
        dGError("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
1,948!
150
      }
151

152
      vmSendRsp(pMsg, code);
1,948✔
153
    }
154

155
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
3,500,962!
156
    rpcFreeCont(pMsg->pCont);
3,500,962✔
157
    taosFreeQitem(pMsg);
3,501,145✔
158
  }
159
}
3,468,747✔
160

161
static void vmProcessStreamReaderQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
58,190✔
162
  SVnodeObj *pVnode = pInfo->ahandle;
58,190✔
163
  SRpcMsg   *pMsg = NULL;
58,190✔
164

165
  for (int32_t i = 0; i < numOfMsgs; ++i) {
122,124✔
166
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
63,901!
167
    const STraceId *trace = &pMsg->info.traceId;
63,920✔
168
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
63,920!
169

170
    terrno = 0;
63,920✔
171
    int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
63,905✔
172
    if (code != 0) {
63,898✔
173
      if (code == -1 && terrno != 0) {
177!
174
        code = terrno;
×
175
      }
176

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

184
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
63,898!
185
    rpcFreeCont(pMsg->pCont);
63,898✔
186
    taosFreeQitem(pMsg);
63,937✔
187
  }
188
}
58,223✔
189

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

194
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,420,720✔
195
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
754,384!
196
    const STraceId *trace = &pMsg->info.traceId;
754,487✔
197
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
754,487!
198

199
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
754,487✔
200
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
754,535!
201
    rpcFreeCont(pMsg->pCont);
754,535✔
202
    taosFreeQitem(pMsg);
754,520✔
203
  }
204
}
666,336✔
205

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

215
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
1,847,667✔
216
  STfs *pTfs = pVnode->pImpl->pTfs;
1,847,667✔
217
  if (pTfs) {
1,847,667!
218
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
1,847,704✔
219
  } else {
220
    return osDataSpaceSufficient();
×
221
  }
222
}
223

224
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
7,981,849✔
225
  *pNode = vmAcquireVnode(pMgt, vgId);
7,981,849✔
226
  if (*pNode == NULL) {
7,982,715✔
227
    return terrno;
9,045✔
228
  }
229
  return 0;
7,973,670✔
230
}
231
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
7,981,851✔
232
  int32_t         code = 0;
7,981,851✔
233
  const STraceId *trace = &pMsg->info.traceId;
7,981,851✔
234
  if (pMsg->contLen < sizeof(SMsgHead)) {
7,981,851!
235
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
236
            pMsg->contLen);
237
    return TSDB_CODE_INVALID_MSG;
×
238
  }
239

240
  SMsgHead *pHead = pMsg->pCont;
7,981,851✔
241

242
  pHead->contLen = ntohl(pHead->contLen);
7,981,851✔
243
  pHead->vgId = ntohl(pHead->vgId);
7,981,851✔
244

245
  SVnodeObj *pVnode = NULL;
7,981,851✔
246
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
7,981,851✔
247
  if (code != 0) {
7,982,720✔
248
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
9,070!
249
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
250
    return code;
9,070✔
251
  }
252

253
  switch (qtype) {
7,973,650✔
254
    case QUERY_QUEUE:
1,349,931✔
255
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
1,349,931✔
256
      if (code) {
1,349,963!
257
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
258
      } else {
259
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,349,963!
260
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
1,349,963✔
261
      }
262
      break;
1,350,021✔
263
    case FETCH_QUEUE:
3,500,746✔
264
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
3,500,746!
265
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
3,500,746✔
266
      break;
3,500,999✔
267
    case WRITE_QUEUE:
1,847,682✔
268
      if (!vmDataSpaceSufficient(pVnode)) {
1,847,682!
269
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
270
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
271
               tstrerror(code), TMSG_INFO(pMsg->msgType));
272
        break;
×
273
      }
274
#if 0
275
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
276
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
277
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
278
               tstrerror(code), TMSG_INFO(pMsg->msgType));
279
        break;
280
      }
281
#endif
282
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
1,847,681✔
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
344!
284
               TMSG_INFO(pMsg->msgType));
285
        code = TSDB_CODE_VND_STOPPED;
344✔
286
        break;
344✔
287
      }
288
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,847,337!
289
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
1,847,339✔
290
      break;
1,847,339✔
291
    case SYNC_QUEUE:
650,470✔
292
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
650,470!
293
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
650,470✔
294
      break;
650,471✔
295
    case SYNC_RD_QUEUE:
104,067✔
296
      if(tsSyncLogHeartbeat){
104,067!
297
        dGInfo("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
×
298
      }
299
      else{
300
        dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
104,067!
301
      }
302
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
104,067✔
303
      break;
104,067✔
304
    case APPLY_QUEUE:
456,265✔
305
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
456,265!
306
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
456,265✔
307
      break;
456,263✔
308
    case STREAM_READER_QUEUE:
63,895✔
309
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
63,895!
310
              TMSG_INFO(pMsg->msgType));
311
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
63,895✔
312
      break;
63,917✔
313
    default:
594✔
314
      code = TSDB_CODE_INVALID_MSG;
594✔
315
      break;
594✔
316
  }
317

318
  vmReleaseVnode(pMgmt, pVnode);
7,974,015✔
319
  return code;
7,973,634✔
320
}
321

322
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
104,692✔
323

324
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
458,034✔
325

326
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
1,844,056✔
327

328
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
1,307,822✔
329

330
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
3,501,044✔
331

332
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
63,872✔
333

334
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
9,754✔
335
  const STraceId *trace = &pMsg->info.traceId;
9,754✔
336
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
9,754!
337
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
9,754✔
338
}
339

340
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
8,941✔
341
  const STraceId *trace = &pMsg->info.traceId;
8,941✔
342
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
8,941!
343
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
8,941✔
344
}
345

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

356
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
702,499✔
357
  SRpcMsg *pMsg;
358
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
702,499✔
359
  if (code) {
702,498!
360
    rpcFreeCont(pRpc->pCont);
×
361
    pRpc->pCont = NULL;
×
362
    return code;
×
363
  }
364

365
  SMsgHead *pHead = pRpc->pCont;
702,498✔
366
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
702,498!
367

368
  pHead->contLen = htonl(pHead->contLen);
702,498✔
369
  pHead->vgId = htonl(pHead->vgId);
702,498✔
370
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
702,498✔
371
  pRpc->pCont = NULL;
702,498✔
372

373
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
702,498✔
374
  if (code != 0) {
702,491✔
375
    dTrace("msg:%p, is freed", pMsg);
4,234✔
376
    rpcFreeCont(pMsg->pCont);
4,234✔
377
    taosFreeQitem(pMsg);
4,234✔
378
  }
379

380
  return code;
702,491✔
381
}
382

383
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
49,061✔
384
  int32_t    size = -1;
49,061✔
385
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
49,061✔
386
  if (pVnode != NULL) {
49,063✔
387
    switch (qtype) {
24,677!
388
      case WRITE_QUEUE:
×
389
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
390
        break;
×
391
      case SYNC_QUEUE:
×
392
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
393
        break;
×
394
      case APPLY_QUEUE:
24,677✔
395
        size = taosQueueItemSize(pVnode->pApplyW.queue);
24,677✔
396
        break;
24,677✔
397
      case QUERY_QUEUE:
×
398
        size = taosQueueItemSize(pVnode->pQueryQ);
×
399
        break;
×
400
      case FETCH_QUEUE:
×
401
        size = taosQueueItemSize(pVnode->pFetchQ);
×
402
        break;
×
403
      case STREAM_READER_QUEUE:
×
404
        size = taosQueueItemSize(pVnode->pStreamReaderQ);
×
405
        break;
×
406
      default:
×
407
        break;
×
408
    }
409
  }
410
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
49,063✔
411
  if (size < 0) {
49,059✔
412
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
24,381✔
413
    size = 0;
24,382✔
414
  }
415
  return size;
49,060✔
416
}
417

418
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
12,221✔
419
  int32_t         code = 0;
12,221✔
420
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
12,221✔
421
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
12,221✔
422
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
12,221✔
423
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
12,221✔
424
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
12,221✔
425
  if (code) {
12,221!
426
    return code;
×
427
  }
428
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
12,221✔
429
  if (code) {
12,221!
430
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
431
    return code;
×
432
  }
433
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
12,221✔
434
  if (code) {
12,221!
435
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
436
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
437
    return code;
×
438
  }
439
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
12,221✔
440
  if (code) {
12,221!
441
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
442
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
443
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
444
    return code;
×
445
  }
446

447
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
12,221✔
448
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
12,221✔
449

450
  // init stream msg processing queue family
451
  pVnode->pStreamReaderQ = tWWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, vmProcessStreamReaderQueue);
12,221✔
452

453
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
12,221!
454
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
12,221!
455
    return TSDB_CODE_OUT_OF_MEMORY;
×
456
  }
457

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

474
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
12,219✔
475
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
12,219✔
476
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
12,221✔
477
  tWWorkerFreeQueue(&pMgmt->streamReaderPool, pVnode->pStreamReaderQ);
12,221✔
478
  pVnode->pQueryQ = NULL;
12,221✔
479
  pVnode->pFetchQ = NULL;
12,221✔
480

481
  pVnode->pFetchQ = NULL;
12,221✔
482
  pVnode->pStreamReaderQ = NULL;
12,221✔
483
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
12,221✔
484
}
12,221✔
485

486
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
2,365✔
487
  int32_t code = 0;
2,365✔
488

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

495
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
2,365✔
496

497
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
2,365✔
498
  pFPool->name = "vnode-fetch";
2,365✔
499
  pFPool->max = tsNumOfVnodeFetchThreads;
2,365✔
500
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
2,365!
501

502
  SSingleWorkerCfg mgmtCfg = {
2,365✔
503
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
504

505
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
2,365!
506

507
  int32_t threadNum = 0;
2,365✔
508
  if (tsNumOfCores == 1) {
2,365!
509
    threadNum = 2;
×
510
  } else {
511
    threadNum = tsNumOfCores;
2,365✔
512
  }
513
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
2,365✔
514
                                   .max = threadNum,
515
                                   .name = "vnode-multi-mgmt",
516
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
517
                                   .param = pMgmt};
518

519
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
2,365!
520

521
  SWWorkerPool *pStreamReaderPool = &pMgmt->streamReaderPool;
2,365✔
522
  pStreamReaderPool->name = "vnode-st-reader";
2,365✔
523
  pStreamReaderPool->max = tsNumOfVnodeStreamReaderThreads;
2,365✔
524
  if ((code = tWWorkerInit(pStreamReaderPool)) != 0) return code;
2,365!
525

526
/*
527
  SSingleWorkerCfg runnerWorkerCfg = {.min = tsNumOfStreamRunnerThreads,
528
                                      .max = tsNumOfStreamRunnerThreads,
529
                                      .name = "vnode-st-runner",
530
                                      .fp = (FItem)NULL,
531
                                      .param = pMgmt};
532
  if ((code = tSingleWorkerInit(&pMgmt->streamRunnerWorker, &runnerWorkerCfg)) != 0) return code;
533
*/
534

535
  dDebug("vnode workers are initialized");
2,365✔
536
  return 0;
2,365✔
537
}
538

539
void vmStopWorker(SVnodeMgmt *pMgmt) {
2,365✔
540
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
2,365✔
541
  tWWorkerCleanup(&pMgmt->fetchPool);
2,365✔
542
  tWWorkerCleanup(&pMgmt->streamReaderPool);
2,365✔
543
//  tSingleWorkerCleanup(&pMgmt->streamRunnerWorker);
544
  dDebug("vnode workers are closed");
2,365✔
545
}
2,365✔
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