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

taosdata / TDengine / #3646

12 Mar 2025 12:34PM UTC coverage: 28.375% (-27.8%) from 56.156%
#3646

push

travis-ci

web-flow
Merge pull request #30119 from taosdata/ciup30

ci: Update workflow to fix param issue of run_tdgpt_test

59085 of 286935 branches covered (20.59%)

Branch coverage included in aggregate %.

102775 of 283490 relevant lines covered (36.25%)

55149.72 hits per line

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

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

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

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

43
  if (IsReq(pMsg)) {
44!
44
    if (code != 0) {
44!
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);
44✔
49
  }
50

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

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

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

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

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

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

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

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

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

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

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

145
  while (1) {
×
146
    if (taosGetQitem(pQall, &pItem) == 0) {
×
147
      break;
×
148
    }
149

150
    SRpcMsg        *pMsg = pItem;
×
151
    const STraceId *trace = &pMsg->info.traceId;
×
152

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

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

168
static void vmProcessStreamChkptQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
×
169
  SVnodeObj *pVnode = pInfo->ahandle;
×
170
  void      *pItem = NULL;
×
171
  int32_t    code = 0;
×
172

173
  while (1) {
×
174
    if (taosGetQitem(pQall, &pItem) == 0) {
×
175
      break;
×
176
    }
177

178
    SRpcMsg        *pMsg = pItem;
×
179
    const STraceId *trace = &pMsg->info.traceId;
×
180

181
    dGTrace("vgId:%d, msg:%p get from vnode-stream-chkpt queue", pVnode->vgId, pMsg);
×
182
    code = vnodeProcessStreamChkptMsg(pVnode->pImpl, pMsg, pInfo);
×
183
    if (code != 0) {
×
184
      terrno = code;
×
185
      dGError("vgId:%d, msg:%p failed to process stream chkpt msg %s since %s", pVnode->vgId, pMsg,
×
186
              TMSG_INFO(pMsg->msgType), tstrerror(code));
187
      vmSendRsp(pMsg, code);
×
188
    }
189

190
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
191
    rpcFreeCont(pMsg->pCont);
×
192
    taosFreeQitem(pMsg);
×
193
  }
194
}
×
195

196
static void vmProcessStreamLongExecQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
×
197
  SVnodeObj      *pVnode = pInfo->ahandle;
×
198
  const STraceId *trace = &pMsg->info.traceId;
×
199
  int32_t         code = 0;
×
200

201
  dGTrace("vgId:%d, msg:%p get from vnode-stream long-exec queue", pVnode->vgId, pMsg);
×
202

203
  code = vnodeProcessStreamLongExecMsg(pVnode->pImpl, pMsg, pInfo);
×
204
  if (code != 0) {
×
205
    terrno = code;
×
206
    dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
×
207
            tstrerror(code));
208
    vmSendRsp(pMsg, code);
×
209
  }
210

211
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
×
212
  rpcFreeCont(pMsg->pCont);
×
213
  taosFreeQitem(pMsg);
×
214
}
×
215

216
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
43,021✔
217
  SVnodeObj *pVnode = pInfo->ahandle;
43,021✔
218
  SRpcMsg   *pMsg = NULL;
43,021✔
219

220
  for (int32_t i = 0; i < numOfMsgs; ++i) {
86,383✔
221
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
43,352!
222
    const STraceId *trace = &pMsg->info.traceId;
43,356✔
223
    dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
43,356!
224

225
    terrno = 0;
43,356✔
226
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
43,349✔
227
    if (code != 0) {
43,364!
228
      if (code == -1 && terrno != 0) {
×
229
        code = terrno;
×
230
      }
231

232
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
×
233
        dGDebug("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
234
      } else {
235
        dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
236
      }
237

238
      vmSendRsp(pMsg, code);
×
239
    }
240

241
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
43,364!
242
    rpcFreeCont(pMsg->pCont);
43,364✔
243
    taosFreeQitem(pMsg);
43,363✔
244
  }
245
}
43,031✔
246

247
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
3,696✔
248
  SVnodeObj *pVnode = pInfo->ahandle;
3,696✔
249
  SRpcMsg   *pMsg = NULL;
3,696✔
250

251
  for (int32_t i = 0; i < numOfMsgs; ++i) {
7,633✔
252
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
3,936!
253
    const STraceId *trace = &pMsg->info.traceId;
3,937✔
254
    dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
3,937!
255

256
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
3,937✔
257
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
3,935!
258
    rpcFreeCont(pMsg->pCont);
3,935✔
259
    taosFreeQitem(pMsg);
3,939✔
260
  }
261
}
3,697✔
262

263
static void vmSendResponse(SRpcMsg *pMsg) {
×
264
  if (pMsg->info.handle) {
×
265
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
266
    if (rpcSendResponse(&rsp) != 0) {
×
267
      dError("failed to send response since %s", terrstr());
×
268
    }
269
  }
270
}
×
271

272
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
28,422✔
273
  STfs *pTfs = pVnode->pImpl->pTfs;
28,422✔
274
  if (pTfs) {
28,422!
275
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
28,423✔
276
  } else {
277
    return osDataSpaceSufficient();
×
278
  }
279
}
280

281
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
99,870✔
282
  *pNode = vmAcquireVnode(pMgt, vgId);
99,870✔
283
  if (*pNode == NULL) {
99,872✔
284
    return terrno;
136✔
285
  }
286
  return 0;
99,736✔
287
}
288
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
99,869✔
289
  int32_t         code = 0;
99,869✔
290
  const STraceId *trace = &pMsg->info.traceId;
99,869✔
291
  if (pMsg->contLen < sizeof(SMsgHead)) {
99,869!
292
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
293
            pMsg->contLen);
294
    return TSDB_CODE_INVALID_MSG;
×
295
  }
296

297
  SMsgHead *pHead = pMsg->pCont;
99,869✔
298

299
  pHead->contLen = ntohl(pHead->contLen);
99,869✔
300
  pHead->vgId = ntohl(pHead->vgId);
99,869✔
301

302
  SVnodeObj *pVnode = NULL;
99,869✔
303
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
99,869✔
304
  if (code != 0) {
99,872✔
305
    dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
136!
306
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
307
    return code;
136✔
308
  }
309

310
  switch (qtype) {
99,736!
311
    case QUERY_QUEUE:
18,375✔
312
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
18,375✔
313
      if (code) {
18,377!
314
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
315
      } else {
316
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
18,377!
317
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
18,377✔
318
      }
319
      break;
18,377✔
320
    case STREAM_QUEUE:
424✔
321
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
424!
322
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
424✔
323
      break;
424✔
324
    case STREAM_CTRL_QUEUE:
×
325
      dGTrace("vgId:%d, msg:%p put into vnode-stream-ctrl queue", pVnode->vgId, pMsg);
×
326
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
×
327
      break;
×
328
    case STREAM_LONG_EXEC_QUEUE:
×
329
      dGTrace("vgId:%d, msg:%p put into vnode-stream-long-exec queue", pVnode->vgId, pMsg);
×
330
      code = taosWriteQitem(pVnode->pStreamLongExecQ, pMsg);
×
331
      break;
×
332
    case STREAM_CHKPT_QUEUE:
×
333
      dGTrace("vgId:%d, msg:%p put into vnode-stream-chkpt queue", pVnode->vgId, pMsg);
×
334
      code = taosWriteQitem(pVnode->pStreamChkQ, pMsg);
×
335
      break;
×
336
    case FETCH_QUEUE:
43,362✔
337
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
43,362!
338
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
43,362✔
339
      break;
43,363✔
340
    case WRITE_QUEUE:
28,422✔
341
      if (!vmDataSpaceSufficient(pVnode)) {
28,422!
342
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
343
        dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
344
        break;
×
345
      }
346
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
28,422!
347
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
×
348
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
349
        break;
×
350
      }
351
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
28,421!
352
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
×
353
        code = TSDB_CODE_VND_STOPPED;
×
354
        break;
×
355
      }
356
      dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
28,421!
357
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
28,421✔
358
      break;
28,415✔
359
    case SYNC_QUEUE:
2,975✔
360
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
2,975!
361
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
2,975✔
362
      break;
2,975✔
363
    case SYNC_RD_QUEUE:
963✔
364
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
963!
365
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
963✔
366
      break;
964✔
367
    case APPLY_QUEUE:
5,210✔
368
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
5,210!
369
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
5,210✔
370
      break;
5,210✔
371
    default:
5✔
372
      code = TSDB_CODE_INVALID_MSG;
5✔
373
      break;
5✔
374
  }
375

376
  vmReleaseVnode(pMgmt, pVnode);
99,733✔
377
  return code;
99,731✔
378
}
379

380
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
974✔
381

382
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
1,854✔
383

384
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
28,335✔
385

386
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
18,035✔
387

388
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
43,369✔
389

390
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
×
391

392
int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CTRL_QUEUE); }
×
393

394
int32_t vmPutMsgToStreamLongExecQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_LONG_EXEC_QUEUE); }
×
395

396
int32_t vmPutMsgToStreamChkQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CHKPT_QUEUE); }
×
397

398
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
44✔
399
  const STraceId *trace = &pMsg->info.traceId;
44✔
400
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
44!
401
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
44✔
402
}
403

404
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
631✔
405
  const STraceId *trace = &pMsg->info.traceId;
631✔
406
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
631!
407
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
631✔
408
}
409

410
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
7,305✔
411
  int32_t code;
412
  if (pRpc->contLen < sizeof(SMsgHead)) {
7,305!
413
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
414
           pRpc->contLen);
415
    rpcFreeCont(pRpc->pCont);
×
416
    pRpc->pCont = NULL;
×
417
    return TSDB_CODE_INVALID_MSG;
×
418
  }
419

420
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
7,305✔
421
  SRpcMsg *pMsg;
422
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
7,305✔
423
  if (code) {
7,305!
424
    rpcFreeCont(pRpc->pCont);
×
425
    pRpc->pCont = NULL;
×
426
    return code;
×
427
  }
428

429
  SMsgHead *pHead = pRpc->pCont;
7,305✔
430
  dTrace("vgId:%d, msg:%p is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
7,305!
431

432
  pHead->contLen = htonl(pHead->contLen);
7,305✔
433
  pHead->vgId = htonl(pHead->vgId);
7,305✔
434
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
7,305✔
435
  pRpc->pCont = NULL;
7,305✔
436

437
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
7,305✔
438
  if (code != 0) {
7,304✔
439
    dTrace("msg:%p, is freed", pMsg);
112!
440
    rpcFreeCont(pMsg->pCont);
112✔
441
    taosFreeQitem(pMsg);
111✔
442
  }
443

444
  return code;
7,303✔
445
}
446

447
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
1,250✔
448
  int32_t    size = -1;
1,250✔
449
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
1,250✔
450
  if (pVnode != NULL) {
1,250✔
451
    switch (qtype) {
738!
452
      case WRITE_QUEUE:
×
453
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
454
        break;
×
455
      case SYNC_QUEUE:
×
456
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
457
        break;
×
458
      case APPLY_QUEUE:
738✔
459
        size = taosQueueItemSize(pVnode->pApplyW.queue);
738✔
460
        break;
738✔
461
      case QUERY_QUEUE:
×
462
        size = taosQueueItemSize(pVnode->pQueryQ);
×
463
        break;
×
464
      case FETCH_QUEUE:
×
465
        size = taosQueueItemSize(pVnode->pFetchQ);
×
466
        break;
×
467
      case STREAM_QUEUE:
×
468
        size = taosQueueItemSize(pVnode->pStreamQ);
×
469
        break;
×
470
      case STREAM_CTRL_QUEUE:
×
471
        size = taosQueueItemSize(pVnode->pStreamCtrlQ);
×
472
        break;
×
473
      case STREAM_LONG_EXEC_QUEUE:
×
474
        size = taosQueueItemSize(pVnode->pStreamLongExecQ);
×
475
        break;
×
476
      case STREAM_CHKPT_QUEUE:
×
477
        size = taosQueueItemSize(pVnode->pStreamChkQ);
×
478
      default:
×
479
        break;
×
480
    }
481
  }
482
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
1,250✔
483
  if (size < 0) {
1,250✔
484
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
512!
485
    size = 0;
512✔
486
  }
487
  return size;
1,250✔
488
}
489

490
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
256✔
491
  int32_t         code = 0;
256✔
492
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
256✔
493
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
256✔
494
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
256✔
495
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
256✔
496
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
256✔
497
  if (code) {
256!
498
    return code;
×
499
  }
500
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
256✔
501
  if (code) {
256!
502
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
503
    return code;
×
504
  }
505
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
256✔
506
  if (code) {
256!
507
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
508
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
509
    return code;
×
510
  }
511
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
256✔
512
  if (code) {
256!
513
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
514
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
515
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
516
    return code;
×
517
  }
518

519
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
256✔
520
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
256✔
521

522
  // init stream msg processing queue family
523
  pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue, 2);
256✔
524
  pVnode->pStreamCtrlQ = tWWorkerAllocQueue(&pMgmt->streamCtrlPool, pVnode, (FItems)vmProcessStreamCtrlQueue);
256✔
525
  pVnode->pStreamLongExecQ = tAutoQWorkerAllocQueue(&pMgmt->streamLongExecPool, pVnode, (FItem)vmProcessStreamLongExecQueue, 1);
256✔
526
  pVnode->pStreamChkQ = tWWorkerAllocQueue(&pMgmt->streamChkPool, pVnode, (FItems)vmProcessStreamChkptQueue);
256✔
527

528
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
256!
529
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
256!
530
      || pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL || pVnode->pStreamChkQ == NULL) {
256!
531
    return TSDB_CODE_OUT_OF_MEMORY;
×
532
  }
533

534
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
256!
535
        taosQueueGetThreadId(pVnode->pWriteW.queue));
536
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
256!
537
        taosQueueGetThreadId(pVnode->pSyncW.queue));
538
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
256!
539
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
540
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
256!
541
        taosQueueGetThreadId(pVnode->pApplyW.queue));
542
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
256!
543
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
256!
544
        taosQueueGetThreadId(pVnode->pFetchQ));
545
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
256!
546
  dInfo("vgId:%d, stream-long-exec-queue:%p is alloced", pVnode->vgId, pVnode->pStreamLongExecQ);
256!
547
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
256!
548
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
549
  dInfo("vgId:%d, stream-chk-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamChkQ,
256!
550
        taosQueueGetThreadId(pVnode->pStreamChkQ));
551
  return 0;
256✔
552
}
553

554
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
256✔
555
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
256✔
556
  tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
256✔
557
  tAutoQWorkerFreeQueue(&pMgmt->streamLongExecPool, pVnode->pStreamLongExecQ);
256✔
558
  tWWorkerFreeQueue(&pMgmt->streamCtrlPool, pVnode->pStreamCtrlQ);
256✔
559
  tWWorkerFreeQueue(&pMgmt->streamChkPool, pVnode->pStreamChkQ);
256✔
560
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
256✔
561
  pVnode->pQueryQ = NULL;
256✔
562
  pVnode->pFetchQ = NULL;
256✔
563

564
  pVnode->pStreamQ = NULL;
256✔
565
  pVnode->pStreamCtrlQ = NULL;
256✔
566
  pVnode->pStreamLongExecQ = NULL;
256✔
567

568
  pVnode->pStreamChkQ = NULL;
256✔
569
  pVnode->pFetchQ = NULL;
256✔
570
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
256!
571
}
256✔
572

573
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
16✔
574
  int32_t code = 0;
16✔
575

576
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
16✔
577
  pQPool->name = "vnode-query";
16✔
578
  pQPool->min = tsNumOfVnodeQueryThreads;
16✔
579
  pQPool->max = tsNumOfVnodeQueryThreads;
16✔
580
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
16!
581

582
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
16✔
583

584
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
16✔
585
  pStreamPool->name = "vnode-stream";
16✔
586
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
16✔
587
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
16!
588

589
  SAutoQWorkerPool *pLongExecPool = &pMgmt->streamLongExecPool;
16✔
590
  pLongExecPool->name = "vnode-stream-long-exec";
16✔
591
  pLongExecPool->ratio = tsRatioOfVnodeStreamThreads/3;
16✔
592
  if ((code = tAutoQWorkerInit(pLongExecPool)) != 0) return code;
16!
593

594
  SWWorkerPool *pStreamCtrlPool = &pMgmt->streamCtrlPool;
16✔
595
  pStreamCtrlPool->name = "vnode-stream-ctrl";
16✔
596
  pStreamCtrlPool->max = 1;
16✔
597
  if ((code = tWWorkerInit(pStreamCtrlPool)) != 0) return code;
16!
598

599
  SWWorkerPool *pStreamChkPool = &pMgmt->streamChkPool;
16✔
600
  pStreamChkPool->name = "vnode-stream-chkpt";
16✔
601
  pStreamChkPool->max = 1;
16✔
602
  if ((code = tWWorkerInit(pStreamChkPool)) != 0) return code;
16!
603

604
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
16✔
605
  pFPool->name = "vnode-fetch";
16✔
606
  pFPool->max = tsNumOfVnodeFetchThreads;
16✔
607
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
16!
608

609
  SSingleWorkerCfg mgmtCfg = {
16✔
610
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
611

612
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
16!
613

614
  int32_t threadNum = 0;
16✔
615
  if (tsNumOfCores == 1) {
16!
616
    threadNum = 2;
×
617
  } else {
618
    threadNum = tsNumOfCores;
16✔
619
  }
620
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
16✔
621
                                   .max = threadNum,
622
                                   .name = "vnode-multi-mgmt",
623
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
624
                                   .param = pMgmt};
625

626
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
16!
627

628
  dDebug("vnode workers are initialized");
16!
629
  return 0;
16✔
630
}
631

632
void vmStopWorker(SVnodeMgmt *pMgmt) {
16✔
633
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
16✔
634
  tAutoQWorkerCleanup(&pMgmt->streamPool);
16✔
635
  tAutoQWorkerCleanup(&pMgmt->streamLongExecPool);
16✔
636
  tWWorkerCleanup(&pMgmt->streamCtrlPool);
16✔
637
  tWWorkerCleanup(&pMgmt->streamChkPool);
16✔
638
  tWWorkerCleanup(&pMgmt->fetchPool);
16✔
639
  dDebug("vnode workers are closed");
16!
640
}
16✔
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