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

taosdata / TDengine / #4609

28 Jul 2025 03:45AM UTC coverage: 60.413% (-0.7%) from 61.072%
#4609

push

travis-ci

web-flow
merge: from 3.3.6 to main branch #32314 

Merge/3.3.6tomain

138583 of 291345 branches covered (47.57%)

Branch coverage included in aggregate %.

79 of 97 new or added lines in 12 files covered. (81.44%)

9880 existing lines in 148 files now uncovered.

208900 of 283831 relevant lines covered (73.6%)

18073489.5 hits per line

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

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

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
11,725!
37
  switch (pMsg->msgType) {
11,725!
38
    case TDMT_DND_CREATE_VNODE:
11,908✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
11,908✔
40
      break;
11,910✔
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)) {
11,727!
52
    if (code != 0) {
11,924✔
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);
11,924✔
57
  }
58

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

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

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

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

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

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

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

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

134
  for (int32_t i = 0; i < numOfMsgs; ++i) {
40,857,523✔
135
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
20,696,346!
136
    const STraceId *trace = &pMsg->info.traceId;
20,700,149✔
137
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
20,700,149!
138

139
    terrno = 0;
20,700,154✔
140
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
20,691,358✔
141
    if (code != 0) {
20,699,136✔
142
      if (code == -1 && terrno != 0) {
3,404!
143
        code = terrno;
×
144
      }
145

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

152
      vmSendRsp(pMsg, code);
3,404✔
153
    }
154

155
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
20,699,136!
156
    rpcFreeCont(pMsg->pCont);
20,699,136✔
157
    taosFreeQitem(pMsg);
20,707,671✔
158
  }
159
}
20,161,177✔
160

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

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

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

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

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

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

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

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

224
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
51,267,987✔
225
  *pNode = vmAcquireVnode(pMgt, vgId);
51,267,987✔
226
  if (*pNode == NULL) {
51,339,378✔
227
    return terrno;
15,965✔
228
  }
229
  return 0;
51,323,413✔
230
}
231
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
51,264,071✔
232
  int32_t         code = 0;
51,264,071✔
233
  const STraceId *trace = &pMsg->info.traceId;
51,264,071✔
234
  if (pMsg->contLen < sizeof(SMsgHead)) {
51,264,071!
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;
51,264,071✔
241

242
  pHead->contLen = ntohl(pHead->contLen);
51,264,071✔
243
  pHead->vgId = ntohl(pHead->vgId);
51,264,071✔
244

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

253
  switch (qtype) {
51,307,982✔
254
    case QUERY_QUEUE:
7,930,251✔
255
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
7,930,251✔
256
      if (code) {
7,929,739✔
257
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
15!
258
      } else {
259
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
7,929,724!
260
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
7,929,724✔
261
      }
262
      break;
7,931,638✔
263
    case FETCH_QUEUE:
20,683,980✔
264
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
20,683,980!
265
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
20,683,981✔
266
      break;
20,703,841✔
267
    case WRITE_QUEUE:
10,852,129✔
268
      if (!vmDataSpaceSufficient(pVnode)) {
10,852,129!
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) {
10,862,931✔
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
815!
284
               TMSG_INFO(pMsg->msgType));
285
        code = TSDB_CODE_VND_STOPPED;
813✔
286
        break;
813✔
287
      }
288
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
10,862,116!
289
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
10,862,119✔
290
      break;
10,871,710✔
291
    case SYNC_QUEUE:
7,544,266✔
292
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
7,544,266!
293
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
7,544,284✔
294
      break;
7,551,682✔
295
    case SYNC_RD_QUEUE:
151,293✔
296
      if(tsSyncLogHeartbeat){
151,293!
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));
151,293!
301
      }
302
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
151,293✔
303
      break;
151,357✔
304
    case APPLY_QUEUE:
4,087,008✔
305
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
4,087,008!
306
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
4,087,010✔
307
      break;
4,087,009✔
308
    case STREAM_READER_QUEUE:
33,005✔
309
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
33,005!
310
              TMSG_INFO(pMsg->msgType));
311
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
33,005✔
312
      break;
33,035✔
313
    default:
26,050✔
314
      code = TSDB_CODE_INVALID_MSG;
26,050✔
315
      break;
26,050✔
316
  }
317

318
  vmReleaseVnode(pMgmt, pVnode);
51,357,135✔
319
  return code;
51,331,381✔
320
}
321

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

324
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
7,209,769✔
325

326
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
10,847,864✔
327

328
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
7,531,484✔
329

330
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
20,685,761✔
331

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

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

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

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

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

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

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

380
  return code;
4,833,809✔
381
}
382

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

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

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

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

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

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

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

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

495
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
3,299✔
496

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

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

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

507
  int32_t threadNum = 0;
3,299✔
508
  if (tsNumOfCores == 1) {
3,299!
UNCOV
509
    threadNum = 2;
×
510
  } else {
511
    threadNum = tsNumOfCores;
3,299✔
512
  }
513
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
3,299✔
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;
3,299!
520

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

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

533
  dDebug("vnode workers are initialized");
3,299✔
534
  return 0;
3,299✔
535
}
536

537
void vmStopWorker(SVnodeMgmt *pMgmt) {
3,299✔
538
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
3,299✔
539
  tWWorkerCleanup(&pMgmt->fetchPool);
3,299✔
540
  tWWorkerCleanup(&pMgmt->streamReaderPool);
3,299✔
541
  tSingleWorkerCleanup(&pMgmt->streamRunnerWorker);
3,299✔
542
  dDebug("vnode workers are closed");
3,299✔
543
}
3,299✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc