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

taosdata / TDengine / #3610

12 Feb 2025 09:54AM UTC coverage: 54.713% (-8.4%) from 63.066%
#3610

push

travis-ci

web-flow
Merge pull request #29745 from taosdata/fix/TD33664-3.0

fix: --version show information check for 3.0

120957 of 286549 branches covered (42.21%)

Branch coverage included in aggregate %.

190849 of 283342 relevant lines covered (67.36%)

4969786.97 hits per line

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

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

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
5,913!
37
  switch (pMsg->msgType) {
5,913✔
38
    case TDMT_DND_CREATE_VNODE:
5,912✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
5,912✔
40
      break;
5,914✔
41
  }
42

43
  if (IsReq(pMsg)) {
5,915✔
44
    if (code != 0) {
5,914✔
45
      if (terrno != 0) code = terrno;
79✔
46
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
79!
47
    }
48
    vmSendRsp(pMsg, code);
5,914✔
49
  }
50

51
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
5,915!
52
  rpcFreeCont(pMsg->pCont);
5,915✔
53
  taosFreeQitem(pMsg);
5,914✔
54
}
5,914✔
55

56
static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
4,246✔
57
  SVnodeMgmt     *pMgmt = pInfo->ahandle;
4,246✔
58
  int32_t         code = -1;
4,246✔
59
  const STraceId *trace = &pMsg->info.traceId;
4,246✔
60

61
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
4,246!
62
  switch (pMsg->msgType) {
4,246!
63
    case TDMT_DND_CREATE_VNODE:
×
64
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
65
      break;
×
66
    case TDMT_DND_DROP_VNODE:
2,261✔
67
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
2,261✔
68
      break;
2,261✔
69
    case TDMT_VND_ALTER_REPLICA:
388✔
70
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
388✔
71
      break;
388✔
72
    case TDMT_VND_DISABLE_WRITE:
28✔
73
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
28✔
74
      break;
28✔
75
    case TDMT_VND_ALTER_HASHRANGE:
28✔
76
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
28✔
77
      break;
28✔
78
    case TDMT_DND_ALTER_VNODE_TYPE:
1,522✔
79
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
1,522✔
80
      break;
1,522✔
81
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
82
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
83
      break;
×
84
    case TDMT_VND_ARB_HEARTBEAT:
19✔
85
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
19✔
86
      break;
19✔
87
    default:
×
88
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
89
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
90
  }
91

92
  if (IsReq(pMsg)) {
4,246!
93
    if (code != 0) {
4,246✔
94
      if (terrno != 0) code = terrno;
1,441!
95
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
1,441!
96
    }
97
    vmSendRsp(pMsg, code);
4,246✔
98
  }
99

100
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
4,246!
101
  rpcFreeCont(pMsg->pCont);
4,246✔
102
  taosFreeQitem(pMsg);
4,246✔
103
}
4,246✔
104

105
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
1,365,816✔
106
  SVnodeObj      *pVnode = pInfo->ahandle;
1,365,816✔
107
  const STraceId *trace = &pMsg->info.traceId;
1,365,816✔
108

109
  dGTrace("vgId:%d, msg:%p get from vnode-query queue", pVnode->vgId, pMsg);
1,365,816!
110
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
1,365,816✔
111
  if (code != 0) {
1,364,673✔
112
    if (terrno != 0) code = terrno;
1,372✔
113
    dGError("vgId:%d, msg:%p failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
1,372!
114
    vmSendRsp(pMsg, code);
1,372✔
115
  }
116

117
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,364,673!
118
  rpcFreeCont(pMsg->pCont);
1,364,673✔
119
  taosFreeQitem(pMsg);
1,365,865✔
120
}
1,365,907✔
121

122
static void vmProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
70,405✔
123
  SVnodeObj      *pVnode = pInfo->ahandle;
70,405✔
124
  const STraceId *trace = &pMsg->info.traceId;
70,405✔
125

126
  dGTrace("vgId:%d, msg:%p get from vnode-stream queue", pVnode->vgId, pMsg);
70,405!
127
  int32_t code = vnodeProcessStreamMsg(pVnode->pImpl, pMsg, pInfo);
70,405✔
128
  if (code != 0) {
70,416✔
129
    terrno = code;
64✔
130
    dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
64!
131
            tstrerror(code));
132
    vmSendRsp(pMsg, code);
64✔
133
  }
134

135
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
70,416!
136
  rpcFreeCont(pMsg->pCont);
70,415✔
137
  taosFreeQitem(pMsg);
70,417✔
138
}
70,417✔
139

140
static void vmProcessStreamCtrlQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
39,479✔
141
  SVnodeObj *pVnode = pInfo->ahandle;
39,479✔
142
  void      *pItem = NULL;
39,479✔
143
  int32_t    code = 0;
39,479✔
144

145
  while (1) {
52,502✔
146
    if (taosGetQitem(pQall, &pItem) == 0) {
91,981✔
147
      break;
39,479✔
148
    }
149

150
    SRpcMsg        *pMsg = pItem;
52,502✔
151
    const STraceId *trace = &pMsg->info.traceId;
52,502✔
152

153
    dGTrace("vgId:%d, msg:%p get from vnode-ctrl-stream queue", pVnode->vgId, pMsg);
52,502!
154
    code = vnodeProcessStreamCtrlMsg(pVnode->pImpl, pMsg, pInfo);
52,502✔
155
    if (code != 0) {
52,502✔
156
      terrno = code;
21✔
157
      dGError("vgId:%d, msg:%p failed to process stream ctrl msg %s since %s", pVnode->vgId, pMsg,
21!
158
              TMSG_INFO(pMsg->msgType), tstrerror(code));
159
      vmSendRsp(pMsg, code);
21✔
160
    }
161

162
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
52,502!
163
    rpcFreeCont(pMsg->pCont);
52,502✔
164
    taosFreeQitem(pMsg);
52,502✔
165
  }
166
}
39,479✔
167

168
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
3,265,429✔
169
  SVnodeObj *pVnode = pInfo->ahandle;
3,265,429✔
170
  SRpcMsg   *pMsg = NULL;
3,265,429✔
171

172
  for (int32_t i = 0; i < numOfMsgs; ++i) {
6,587,882✔
173
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
3,320,198!
174
    const STraceId *trace = &pMsg->info.traceId;
3,320,573✔
175
    dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
3,320,573!
176

177
    terrno = 0;
3,320,573✔
178
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
3,319,957✔
179
    if (code != 0) {
3,320,484✔
180
      if (code == -1 && terrno != 0) {
589!
181
        code = terrno;
×
182
      }
183

184
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
589!
185
        dGDebug("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
186
      } else {
187
        dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
589!
188
      }
189

190
      vmSendRsp(pMsg, code);
589✔
191
    }
192

193
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
3,320,484!
194
    rpcFreeCont(pMsg->pCont);
3,320,484✔
195
    taosFreeQitem(pMsg);
3,322,369✔
196
  }
197
}
3,267,684✔
198

199
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
514,334✔
200
  SVnodeObj *pVnode = pInfo->ahandle;
514,334✔
201
  SRpcMsg   *pMsg = NULL;
514,334✔
202

203
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,118,858✔
204
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
604,424!
205
    const STraceId *trace = &pMsg->info.traceId;
604,502✔
206
    dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
604,502!
207

208
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
604,502✔
209
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
604,489!
210
    rpcFreeCont(pMsg->pCont);
604,489✔
211
    taosFreeQitem(pMsg);
604,441✔
212
  }
213
}
514,434✔
214

215
static void vmSendResponse(SRpcMsg *pMsg) {
×
216
  if (pMsg->info.handle) {
×
217
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
218
    if (rpcSendResponse(&rsp) != 0) {
×
219
      dError("failed to send response since %s", terrstr());
×
220
    }
221
  }
222
}
×
223

224
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
1,407,863✔
225
  STfs *pTfs = pVnode->pImpl->pTfs;
1,407,863✔
226
  if (pTfs) {
1,407,863!
227
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
1,408,079✔
228
  } else {
229
    return osDataSpaceSufficient();
×
230
  }
231
}
232

233
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
7,219,439✔
234
  *pNode = vmAcquireVnode(pMgt, vgId);
7,219,439✔
235
  if (*pNode == NULL) {
7,231,776✔
236
    return terrno;
9,052✔
237
  }
238
  return 0;
7,222,724✔
239
}
240
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
7,220,125✔
241
  int32_t         code = 0;
7,220,125✔
242
  const STraceId *trace = &pMsg->info.traceId;
7,220,125✔
243
  if (pMsg->contLen < sizeof(SMsgHead)) {
7,220,125!
244
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
245
            pMsg->contLen);
246
    return TSDB_CODE_INVALID_MSG;
×
247
  }
248

249
  SMsgHead *pHead = pMsg->pCont;
7,220,125✔
250

251
  pHead->contLen = ntohl(pHead->contLen);
7,220,125✔
252
  pHead->vgId = ntohl(pHead->vgId);
7,220,125✔
253

254
  SVnodeObj *pVnode = NULL;
7,220,125✔
255
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
7,220,125✔
256
  if (code != 0) {
7,230,236✔
257
    dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
9,041!
258
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
259
    return code;
9,041✔
260
  }
261

262
  switch (qtype) {
7,221,195✔
263
    case QUERY_QUEUE:
1,363,592✔
264
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
1,363,592✔
265
      if (code) {
1,363,866!
266
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
267
      } else {
268
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
1,363,866!
269
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
1,363,866✔
270
      }
271
      break;
1,364,165✔
272
    case STREAM_QUEUE:
70,414✔
273
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
70,414!
274
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
70,415✔
275
      break;
70,416✔
276
    case STREAM_CTRL_QUEUE:
52,493✔
277
      dGTrace("vgId:%d, msg:%p put into vnode-ctrl-stream queue", pVnode->vgId, pMsg);
52,493!
278
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
52,493✔
279
      break;
52,500✔
280
    case FETCH_QUEUE:
3,316,896✔
281
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
3,316,896!
282
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
3,316,900✔
283
      break;
3,319,380✔
284
    case WRITE_QUEUE:
1,407,899✔
285
      if (!vmDataSpaceSufficient(pVnode)) {
1,407,899!
286
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
287
        dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
288
        break;
×
289
      }
290
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
1,407,882!
291
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
×
292
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
293
        break;
×
294
      }
295
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
1,407,840✔
296
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
697!
297
        code = TSDB_CODE_VND_STOPPED;
697✔
298
        break;
697✔
299
      }
300
      dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
1,407,143!
301
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
1,407,144✔
302
      break;
1,407,318✔
303
    case SYNC_QUEUE:
542,593✔
304
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
542,593!
305
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
542,593✔
306
      break;
542,561✔
307
    case SYNC_RD_QUEUE:
61,803✔
308
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
61,803!
309
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
61,803✔
310
      break;
61,875✔
311
    case APPLY_QUEUE:
399,346✔
312
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
399,346!
313
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
399,346✔
314
      break;
399,350✔
315
    default:
6,159✔
316
      code = TSDB_CODE_INVALID_MSG;
6,159✔
317
      break;
6,159✔
318
  }
319

320
  vmReleaseVnode(pMgmt, pVnode);
7,224,421✔
321
  return code;
7,222,441✔
322
}
323

324
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
62,747✔
325

326
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
400,319✔
327

328
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
1,396,064✔
329

330
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
1,320,958✔
331

332
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
3,317,156✔
333

334
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
13,692✔
335

336
int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CTRL_QUEUE); }
52,530✔
337

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

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

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

360
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
659,492✔
361
  SRpcMsg *pMsg;
362
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
659,492✔
363
  if (code) {
659,510!
364
    rpcFreeCont(pRpc->pCont);
×
365
    pRpc->pCont = NULL;
×
366
    return code;
×
367
  }
368

369
  SMsgHead *pHead = pRpc->pCont;
659,510✔
370
  dTrace("vgId:%d, msg:%p is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
659,510!
371

372
  pHead->contLen = htonl(pHead->contLen);
659,511✔
373
  pHead->vgId = htonl(pHead->vgId);
659,511✔
374
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
659,511✔
375
  pRpc->pCont = NULL;
659,511✔
376

377
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
659,511✔
378
  if (code != 0) {
659,504✔
379
    dTrace("msg:%p, is freed", pMsg);
2,831✔
380
    rpcFreeCont(pMsg->pCont);
2,831✔
381
    taosFreeQitem(pMsg);
2,831✔
382
  }
383

384
  return code;
659,484✔
385
}
386

387
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
137,578✔
388
  int32_t    size = -1;
137,578✔
389
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
137,578✔
390
  if (pVnode != NULL) {
137,655✔
391
    switch (qtype) {
123,946!
392
      case WRITE_QUEUE:
×
393
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
394
        break;
×
395
      case SYNC_QUEUE:
×
396
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
397
        break;
×
398
      case APPLY_QUEUE:
123,942✔
399
        size = taosQueueItemSize(pVnode->pApplyW.queue);
123,942✔
400
        break;
123,946✔
401
      case QUERY_QUEUE:
×
402
        size = taosQueueItemSize(pVnode->pQueryQ);
×
403
        break;
×
404
      case FETCH_QUEUE:
×
405
        size = taosQueueItemSize(pVnode->pFetchQ);
×
406
        break;
×
407
      case STREAM_QUEUE:
×
408
        size = taosQueueItemSize(pVnode->pStreamQ);
×
409
        break;
×
410
      case STREAM_CTRL_QUEUE:
×
411
        size = taosQueueItemSize(pVnode->pStreamCtrlQ);
×
412
      default:
×
413
        break;
×
414
    }
415
  }
416
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
137,655✔
417
  if (size < 0) {
137,645✔
418
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
13,701✔
419
    size = 0;
13,701✔
420
  }
421
  return size;
137,645✔
422
}
423

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

453
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
6,714✔
454
  pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
6,714✔
455
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
6,714✔
456
  pVnode->pStreamCtrlQ = tWWorkerAllocQueue(&pMgmt->streamCtrlPool, pVnode, (FItems)vmProcessStreamCtrlQueue);
6,714✔
457

458
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
6,714!
459
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
6,714!
460
      || pVnode->pStreamCtrlQ == NULL) {
6,714!
461
    return TSDB_CODE_OUT_OF_MEMORY;
×
462
  }
463

464
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
6,714!
465
        taosQueueGetThreadId(pVnode->pWriteW.queue));
466
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
6,714!
467
        taosQueueGetThreadId(pVnode->pSyncW.queue));
468
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
6,714!
469
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
470
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
6,714!
471
        taosQueueGetThreadId(pVnode->pApplyW.queue));
472
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
6,714!
473
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
6,714!
474
        taosQueueGetThreadId(pVnode->pFetchQ));
475
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
6,714!
476
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
6,714!
477
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
478
  return 0;
6,714✔
479
}
480

481
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
6,711✔
482
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
6,711✔
483
  tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
6,712✔
484
  tWWorkerFreeQueue(&pMgmt->streamCtrlPool, pVnode->pStreamCtrlQ);
6,712✔
485
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
6,712✔
486
  pVnode->pQueryQ = NULL;
6,712✔
487
  pVnode->pStreamQ = NULL;
6,712✔
488
  pVnode->pStreamCtrlQ = NULL;
6,712✔
489
  pVnode->pFetchQ = NULL;
6,712✔
490
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
6,712✔
491
}
6,712✔
492

493
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
1,280✔
494
  int32_t                code = 0;
1,280✔
495
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
1,280✔
496
  pQPool->name = "vnode-query";
1,280✔
497
  pQPool->min = tsNumOfVnodeQueryThreads;
1,280✔
498
  pQPool->max = tsNumOfVnodeQueryThreads;
1,280✔
499
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
1,280!
500

501
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
1,280✔
502

503
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
1,280✔
504
  pStreamPool->name = "vnode-stream";
1,280✔
505
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
1,280✔
506
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
1,280!
507

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

513
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
1,280✔
514
  pFPool->name = "vnode-fetch";
1,280✔
515
  pFPool->max = tsNumOfVnodeFetchThreads;
1,280✔
516
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
1,280!
517

518
  SSingleWorkerCfg mgmtCfg = {
1,280✔
519
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
520

521
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
1,280!
522

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

535
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
1,280!
536

537
  dDebug("vnode workers are initialized");
1,280✔
538
  return 0;
1,280✔
539
}
540

541
void vmStopWorker(SVnodeMgmt *pMgmt) {
1,280✔
542
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
1,280✔
543
  tAutoQWorkerCleanup(&pMgmt->streamPool);
1,280✔
544
  tWWorkerCleanup(&pMgmt->streamCtrlPool);
1,280✔
545
  tWWorkerCleanup(&pMgmt->fetchPool);
1,280✔
546
  dDebug("vnode workers are closed");
1,280✔
547
}
1,280✔
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