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

taosdata / TDengine / #3611

12 Feb 2025 09:54AM UTC coverage: 63.456% (+8.7%) from 54.713%
#3611

push

travis-ci

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

fix: --version show information check for 3.0

141323 of 286257 branches covered (49.37%)

Branch coverage included in aggregate %.

220096 of 283298 relevant lines covered (77.69%)

19188455.82 hits per line

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

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

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

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

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

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

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

61
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
9,908!
62
  switch (pMsg->msgType) {
9,908!
63
    case TDMT_DND_CREATE_VNODE:
×
64
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
65
      break;
×
66
    case TDMT_DND_DROP_VNODE:
4,335✔
67
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
4,335✔
68
      break;
4,335✔
69
    case TDMT_VND_ALTER_REPLICA:
1,134✔
70
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
1,134✔
71
      break;
1,134✔
72
    case TDMT_VND_DISABLE_WRITE:
42✔
73
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
42✔
74
      break;
42✔
75
    case TDMT_VND_ALTER_HASHRANGE:
42✔
76
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
42✔
77
      break;
42✔
78
    case TDMT_DND_ALTER_VNODE_TYPE:
4,325✔
79
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
4,325✔
80
      break;
4,325✔
81
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
82
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
83
      break;
×
84
    case TDMT_VND_ARB_HEARTBEAT:
30✔
85
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
30✔
86
      break;
30✔
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)) {
9,908!
93
    if (code != 0) {
9,908✔
94
      if (terrno != 0) code = terrno;
4,146!
95
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
4,146!
96
    }
97
    vmSendRsp(pMsg, code);
9,908✔
98
  }
99

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

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

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

117
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
8,046,373!
118
  rpcFreeCont(pMsg->pCont);
8,046,373✔
119
  taosFreeQitem(pMsg);
8,050,643✔
120
}
8,050,735✔
121

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

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

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

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

145
  while (1) {
183,908✔
146
    if (taosGetQitem(pQall, &pItem) == 0) {
336,600✔
147
      break;
152,692✔
148
    }
149

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

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

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

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

172
  for (int32_t i = 0; i < numOfMsgs; ++i) {
39,283,373✔
173
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
19,955,789!
174
    const STraceId *trace = &pMsg->info.traceId;
19,960,704✔
175
    dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
19,960,704!
176

177
    terrno = 0;
19,960,704✔
178
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
19,950,557✔
179
    if (code != 0) {
19,955,686✔
180
      if (code == -1 && terrno != 0) {
1,557!
181
        code = terrno;
×
182
      }
183

184
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
1,557!
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());
1,557!
188
      }
189

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

193
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
19,955,686!
194
    rpcFreeCont(pMsg->pCont);
19,955,686✔
195
    taosFreeQitem(pMsg);
19,967,710✔
196
  }
197
}
19,327,584✔
198

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

203
  for (int32_t i = 0; i < numOfMsgs; ++i) {
8,300,945✔
204
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
5,939,246!
205
    const STraceId *trace = &pMsg->info.traceId;
5,939,528✔
206
    dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
5,939,528!
207

208
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
5,939,528✔
209
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
5,939,217!
210
    rpcFreeCont(pMsg->pCont);
5,939,217✔
211
    taosFreeQitem(pMsg);
5,939,390✔
212
  }
213
}
2,361,699✔
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) {
10,377,764✔
225
  STfs *pTfs = pVnode->pImpl->pTfs;
10,377,764✔
226
  if (pTfs) {
10,377,764!
227
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
10,381,175✔
228
  } else {
229
    return osDataSpaceSufficient();
×
230
  }
231
}
232

233
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
47,739,731✔
234
  *pNode = vmAcquireVnode(pMgt, vgId);
47,739,731✔
235
  if (*pNode == NULL) {
47,836,465✔
236
    return terrno;
17,082✔
237
  }
238
  return 0;
47,819,383✔
239
}
240
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
47,739,867✔
241
  int32_t         code = 0;
47,739,867✔
242
  const STraceId *trace = &pMsg->info.traceId;
47,739,867✔
243
  if (pMsg->contLen < sizeof(SMsgHead)) {
47,739,867!
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;
47,739,867✔
250

251
  pHead->contLen = ntohl(pHead->contLen);
47,739,867✔
252
  pHead->vgId = ntohl(pHead->vgId);
47,739,867✔
253

254
  SVnodeObj *pVnode = NULL;
47,739,867✔
255
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
47,739,867✔
256
  if (code != 0) {
47,813,779✔
257
    dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
18,305!
258
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
259
    return code;
18,305✔
260
  }
261

262
  switch (qtype) {
47,795,474✔
263
    case QUERY_QUEUE:
8,041,842✔
264
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
8,041,842✔
265
      if (code) {
8,041,578✔
266
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
31!
267
      } else {
268
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
8,041,547!
269
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
8,041,547✔
270
      }
271
      break;
8,046,272✔
272
    case STREAM_QUEUE:
190,555✔
273
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
190,555!
274
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
190,554✔
275
      break;
190,654✔
276
    case STREAM_CTRL_QUEUE:
183,337✔
277
      dGTrace("vgId:%d, msg:%p put into vnode-ctrl-stream queue", pVnode->vgId, pMsg);
183,337!
278
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
183,336✔
279
      break;
183,652✔
280
    case FETCH_QUEUE:
19,920,237✔
281
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
19,920,237!
282
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
19,920,236✔
283
      break;
19,962,311✔
284
    case WRITE_QUEUE:
10,378,077✔
285
      if (!vmDataSpaceSufficient(pVnode)) {
10,378,077!
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)) {
10,386,096!
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) {
10,384,734✔
296
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
341!
297
        code = TSDB_CODE_VND_STOPPED;
341✔
298
        break;
341✔
299
      }
300
      dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
10,384,393!
301
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
10,384,393✔
302
      break;
10,398,645✔
303
    case SYNC_QUEUE:
5,786,875✔
304
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
5,786,875!
305
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
5,786,875✔
306
      break;
5,794,842✔
307
    case SYNC_RD_QUEUE:
143,364✔
308
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
143,364!
309
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
143,364✔
310
      break;
143,537✔
311
    case APPLY_QUEUE:
3,095,480✔
312
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
3,095,480!
313
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
3,095,480✔
314
      break;
3,095,462✔
315
    default:
55,707✔
316
      code = TSDB_CODE_INVALID_MSG;
55,707✔
317
      break;
55,707✔
318
  }
319

320
  vmReleaseVnode(pMgmt, pVnode);
47,871,423✔
321
  return code;
47,826,281✔
322
}
323

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

326
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
5,425,379✔
327

328
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
10,348,738✔
329

330
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
7,604,288✔
331

332
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
19,931,454✔
333

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

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

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

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

350
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
4,099,079✔
351
  int32_t code;
352
  if (pRpc->contLen < sizeof(SMsgHead)) {
4,099,079!
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;
4,099,079✔
361
  SRpcMsg *pMsg;
362
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
4,099,079✔
363
  if (code) {
4,099,101!
364
    rpcFreeCont(pRpc->pCont);
×
365
    pRpc->pCont = NULL;
×
366
    return code;
×
367
  }
368

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

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

377
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
4,099,101✔
378
  if (code != 0) {
4,099,131✔
379
    dTrace("msg:%p, is freed", pMsg);
5,724✔
380
    rpcFreeCont(pMsg->pCont);
5,724✔
381
    taosFreeQitem(pMsg);
5,720✔
382
  }
383

384
  return code;
4,099,123✔
385
}
386

387
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
156,992✔
388
  int32_t    size = -1;
156,992✔
389
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
156,992✔
390
  if (pVnode != NULL) {
157,009✔
391
    switch (qtype) {
133,447!
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:
133,445✔
399
        size = taosQueueItemSize(pVnode->pApplyW.queue);
133,445✔
400
        break;
133,446✔
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);
157,008✔
417
  if (size < 0) {
156,996✔
418
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
23,548✔
419
    size = 0;
23,547✔
420
  }
421
  return size;
156,995✔
422
}
423

424
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
11,658✔
425
  int32_t         code = 0;
11,658✔
426
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
11,658✔
427
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
11,658✔
428
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
11,658✔
429
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
11,658✔
430
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
11,658✔
431
  if (code) {
11,658!
432
    return code;
×
433
  }
434
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
11,658✔
435
  if (code) {
11,658!
436
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
437
    return code;
×
438
  }
439
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
11,658✔
440
  if (code) {
11,658!
441
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
442
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
443
    return code;
×
444
  }
445
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
11,658✔
446
  if (code) {
11,658!
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);
11,658✔
454
  pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
11,658✔
455
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
11,658✔
456
  pVnode->pStreamCtrlQ = tWWorkerAllocQueue(&pMgmt->streamCtrlPool, pVnode, (FItems)vmProcessStreamCtrlQueue);
11,658✔
457

458
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
11,658!
459
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
11,658!
460
      || pVnode->pStreamCtrlQ == NULL) {
11,658!
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,
11,658!
465
        taosQueueGetThreadId(pVnode->pWriteW.queue));
466
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
11,658!
467
        taosQueueGetThreadId(pVnode->pSyncW.queue));
468
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
11,658!
469
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
470
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
11,658!
471
        taosQueueGetThreadId(pVnode->pApplyW.queue));
472
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
11,658!
473
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
11,658!
474
        taosQueueGetThreadId(pVnode->pFetchQ));
475
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
11,658!
476
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
11,658!
477
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
478
  return 0;
11,658✔
479
}
480

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

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

501
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
2,123✔
502

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

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

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

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

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

523
  int32_t threadNum = 0;
2,123✔
524
  if (tsNumOfCores == 1) {
2,123!
525
    threadNum = 2;
×
526
  } else {
527
    threadNum = tsNumOfCores;
2,123✔
528
  }
529
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
2,123✔
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;
2,123!
536

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

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