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

taosdata / TDengine / #4513

17 Jul 2025 02:02AM UTC coverage: 31.359% (-31.1%) from 62.446%
#4513

push

travis-ci

web-flow
Merge pull request #31914 from taosdata/fix/3.0/compare-ans-failed

fix:Convert line endings from LF to CRLF for ans file

68541 of 301034 branches covered (22.77%)

Branch coverage included in aggregate %.

117356 of 291771 relevant lines covered (40.22%)

602262.98 hits per line

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

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

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

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

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

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

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
16!
70
  switch (pMsg->msgType) {
16!
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
16✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
16✔
76
      break;
16✔
77
    case TDMT_VND_ALTER_REPLICA:
×
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
×
79
      break;
×
80
    case TDMT_VND_DISABLE_WRITE:
×
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
×
82
      break;
×
83
    case TDMT_VND_ALTER_HASHRANGE:
×
84
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
×
85
      break;
×
86
    case TDMT_DND_ALTER_VNODE_TYPE:
×
87
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
×
88
      break;
×
89
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
90
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
91
      break;
×
92
    case TDMT_VND_ARB_HEARTBEAT:
×
93
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
×
94
      break;
×
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)) {
16!
101
    if (code != 0) {
16!
102
      if (terrno != 0) code = terrno;
×
103
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
×
104
    }
105
    vmSendRsp(pMsg, code);
16✔
106
  }
107

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

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

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

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

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

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

139
    terrno = 0;
42,441✔
140
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
42,436✔
141
    if (code != 0) {
42,449!
142
      if (code == -1 && terrno != 0) {
×
143
        code = terrno;
×
144
      }
145

146
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
×
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());
×
150
      }
151

152
      vmSendRsp(pMsg, code);
×
153
    }
154

155
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
42,449!
156
    rpcFreeCont(pMsg->pCont);
42,449✔
157
    taosFreeQitem(pMsg);
42,448✔
158
  }
159
}
41,884✔
160

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

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

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

177
      if (code == 0) {
×
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());
×
181
      }
182
    }
183

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

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

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

199
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
167✔
200
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
167!
201
    rpcFreeCont(pMsg->pCont);
167✔
202
    taosFreeQitem(pMsg);
167✔
203
  }
204
}
167✔
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) {
26,175✔
216
  STfs *pTfs = pVnode->pImpl->pTfs;
26,175✔
217
  if (pTfs) {
26,175!
218
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
26,175✔
219
  } else {
220
    return osDataSpaceSufficient();
×
221
  }
222
}
223

224
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
86,784✔
225
  *pNode = vmAcquireVnode(pMgt, vgId);
86,784✔
226
  if (*pNode == NULL) {
86,787✔
227
    return terrno;
16✔
228
  }
229
  return 0;
86,771✔
230
}
231
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
86,783✔
232
  int32_t         code = 0;
86,783✔
233
  const STraceId *trace = &pMsg->info.traceId;
86,783✔
234
  if (pMsg->contLen < sizeof(SMsgHead)) {
86,783!
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;
86,783✔
241

242
  pHead->contLen = ntohl(pHead->contLen);
86,783✔
243
  pHead->vgId = ntohl(pHead->vgId);
86,783✔
244

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

253
  switch (qtype) {
86,770!
254
    case QUERY_QUEUE:
17,926✔
255
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
17,926✔
256
      if (code) {
17,927!
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));
17,927!
260
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
17,927✔
261
      }
262
      break;
17,927✔
263
    case FETCH_QUEUE:
42,447✔
264
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
42,447!
265
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
42,447✔
266
      break;
42,449✔
267
    case WRITE_QUEUE:
26,175✔
268
      if (!vmDataSpaceSufficient(pVnode)) {
26,175!
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) {
26,175!
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
×
284
               TMSG_INFO(pMsg->msgType));
285
        code = TSDB_CODE_VND_STOPPED;
×
286
        break;
×
287
      }
288
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
26,175!
289
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
26,175✔
290
      break;
26,175✔
291
    case SYNC_QUEUE:
167✔
292
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
167!
293
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
167✔
294
      break;
167✔
295
    case SYNC_RD_QUEUE:
×
296
      if(tsSyncLogHeartbeat){
×
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));
×
301
      }
302
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
×
303
      break;
×
304
    case APPLY_QUEUE:
53✔
305
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
53!
306
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
53✔
307
      break;
53✔
308
    case STREAM_READER_QUEUE:
×
309
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
×
310
              TMSG_INFO(pMsg->msgType));
311
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
×
312
      break;
×
313
    default:
2✔
314
      code = TSDB_CODE_INVALID_MSG;
2✔
315
      break;
2✔
316
  }
317

318
  vmReleaseVnode(pMgmt, pVnode);
86,773✔
319
  return code;
86,771✔
320
}
321

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

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

326
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
26,151✔
327

328
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
17,581✔
329

330
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
42,447✔
331

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

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

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

346
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
605✔
347
  int32_t code;
348
  if (pRpc->contLen < sizeof(SMsgHead)) {
605!
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;
605✔
357
  SRpcMsg *pMsg;
358
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
605✔
359
  if (code) {
605!
360
    rpcFreeCont(pRpc->pCont);
×
361
    pRpc->pCont = NULL;
×
362
    return code;
×
363
  }
364

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

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

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

380
  return code;
605✔
381
}
382

383
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
99✔
384
  int32_t    size = -1;
99✔
385
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
99✔
386
  if (pVnode != NULL) {
99✔
387
    switch (qtype) {
33!
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:
33✔
395
        size = taosQueueItemSize(pVnode->pApplyW.queue);
33✔
396
        break;
33✔
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);
99✔
411
  if (size < 0) {
99✔
412
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
66!
413
    size = 0;
66✔
414
  }
415
  return size;
99✔
416
}
417

418
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
53✔
419
  int32_t         code = 0;
53✔
420
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
53✔
421
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
53✔
422
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
53✔
423
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
53✔
424
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
53✔
425
  if (code) {
53!
426
    return code;
×
427
  }
428
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
53✔
429
  if (code) {
53!
430
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
431
    return code;
×
432
  }
433
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
53✔
434
  if (code) {
53!
435
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
436
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
437
    return code;
×
438
  }
439
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
53✔
440
  if (code) {
53!
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);
53✔
448
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
53✔
449

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

453
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
53!
454
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
53!
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,
53!
459
        taosQueueGetThreadId(pVnode->pWriteW.queue));
460
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
53!
461
        taosQueueGetThreadId(pVnode->pSyncW.queue));
462
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
53!
463
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
464
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
53!
465
        taosQueueGetThreadId(pVnode->pApplyW.queue));
466
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
53!
467
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
53!
468
        taosQueueGetThreadId(pVnode->pFetchQ));
469
  dInfo("vgId:%d, stream-reader-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamReaderQ,
53!
470
        taosQueueGetThreadId(pVnode->pStreamReaderQ));
471
  return 0;
53✔
472
}
473

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

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

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

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

495
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
15✔
496

497
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
15✔
498
  pStreamPool->name = "vnode-stream";
15✔
499
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
15✔
500
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
15!
501

502
  SAutoQWorkerPool *pLongExecPool = &pMgmt->streamLongExecPool;
15✔
503
  pLongExecPool->name = "vnode-stream-long-exec";
15✔
504
  pLongExecPool->ratio = tsRatioOfVnodeStreamThreads/3;
15✔
505
  if ((code = tAutoQWorkerInit(pLongExecPool)) != 0) return code;
15!
506

507
  SWWorkerPool *pStreamCtrlPool = &pMgmt->streamCtrlPool;
15✔
508
  pStreamCtrlPool->name = "vnode-stream-ctrl";
15✔
509
  pStreamCtrlPool->max = 4;
15✔
510
  if ((code = tWWorkerInit(pStreamCtrlPool)) != 0) return code;
15!
511

512
  SWWorkerPool *pStreamChkPool = &pMgmt->streamChkPool;
15✔
513
  pStreamChkPool->name = "vnode-stream-chkpt";
15✔
514
  pStreamChkPool->max = 1;
15✔
515
  if ((code = tWWorkerInit(pStreamChkPool)) != 0) return code;
15!
516

517
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
15✔
518
  pFPool->name = "vnode-fetch";
15✔
519
  pFPool->max = tsNumOfVnodeFetchThreads;
15✔
520
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
15!
521

522
  SSingleWorkerCfg mgmtCfg = {
15✔
523
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
524

525
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
15!
526

527
  int32_t threadNum = 0;
15✔
528
  if (tsNumOfCores == 1) {
15!
529
    threadNum = 2;
×
530
  } else {
531
    threadNum = tsNumOfCores;
15✔
532
  }
533
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
15✔
534
                                   .max = threadNum,
535
                                   .name = "vnode-multi-mgmt",
536
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
537
                                   .param = pMgmt};
538

539
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
15!
540

541
  SWWorkerPool *pStreamReaderPool = &pMgmt->streamReaderPool;
15✔
542
  pStreamReaderPool->name = "vnode-st-reader";
15✔
543
  pStreamReaderPool->max = tsNumOfVnodeStreamReaderThreads;
15✔
544
  if ((code = tWWorkerInit(pStreamReaderPool)) != 0) return code;
15!
545

546
  SSingleWorkerCfg runnerWorkerCfg = {.min = tsNumOfStreamRunnerThreads,
15✔
547
                                      .max = tsNumOfStreamRunnerThreads,
548
                                      .name = "vnode-st-runner",
549
                                      .fp = (FItem)NULL,
550
                                      .param = pMgmt};
551
  if ((code = tSingleWorkerInit(&pMgmt->streamRunnerWorker, &runnerWorkerCfg)) != 0) return code;
15!
552

553
  dDebug("vnode workers are initialized");
15!
554
  return 0;
15✔
555
}
556

557
void vmStopWorker(SVnodeMgmt *pMgmt) {
15✔
558
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
15✔
559
  tAutoQWorkerCleanup(&pMgmt->streamPool);
15✔
560
  tAutoQWorkerCleanup(&pMgmt->streamLongExecPool);
15✔
561
  tWWorkerCleanup(&pMgmt->streamCtrlPool);
15✔
562
  tWWorkerCleanup(&pMgmt->streamChkPool);
15✔
563
  tWWorkerCleanup(&pMgmt->fetchPool);
15✔
564
  tWWorkerCleanup(&pMgmt->streamReaderPool);
15✔
565
  tSingleWorkerCleanup(&pMgmt->streamRunnerWorker);
15✔
566
  dDebug("vnode workers are closed");
15!
567
}
15✔
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