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

taosdata / TDengine / #3631

07 Mar 2025 03:18PM UTC coverage: 60.671% (-3.0%) from 63.629%
#3631

push

travis-ci

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

ci: update ci workflow to fix path issue

141481 of 300084 branches covered (47.15%)

Branch coverage included in aggregate %.

223132 of 300884 relevant lines covered (74.16%)

7878557.0 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

145
  while (1) {
159,853✔
146
    if (taosGetQitem(pQall, &pItem) == 0) {
284,141✔
147
      break;
124,288✔
148
    }
149

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

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

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

168
static void vmProcessStreamLongExecQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
2,004✔
169
  SVnodeObj      *pVnode = pInfo->ahandle;
2,004✔
170
  const STraceId *trace = &pMsg->info.traceId;
2,004✔
171
  int32_t         code = 0;
2,004✔
172

173
  dGTrace("vgId:%d, msg:%p get from vnode-stream long-exec queue", pVnode->vgId, pMsg);
2,004!
174

175
  code = vnodeProcessStreamLongExecMsg(pVnode->pImpl, pMsg, pInfo);
2,004✔
176
  if (code != 0) {
2,004!
177
    terrno = code;
×
178
    dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
×
179
            tstrerror(code));
180
    vmSendRsp(pMsg, code);
×
181
  }
182

183
  dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
2,004!
184
  rpcFreeCont(pMsg->pCont);
2,004✔
185
  taosFreeQitem(pMsg);
2,004✔
186
}
2,004✔
187

188
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
3,604,364✔
189
  SVnodeObj *pVnode = pInfo->ahandle;
3,604,364✔
190
  SRpcMsg   *pMsg = NULL;
3,604,364✔
191

192
  for (int32_t i = 0; i < numOfMsgs; ++i) {
7,301,817✔
193
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
3,695,360!
194
    const STraceId *trace = &pMsg->info.traceId;
3,697,006✔
195
    dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
3,697,006!
196

197
    terrno = 0;
3,697,005✔
198
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
3,695,062✔
199
    if (code != 0) {
3,696,630✔
200
      if (code == -1 && terrno != 0) {
1,554!
201
        code = terrno;
×
202
      }
203

204
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
1,554!
205
        dGDebug("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
×
206
      } else {
207
        dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
1,554!
208
      }
209

210
      vmSendRsp(pMsg, code);
1,554✔
211
    }
212

213
    dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
3,696,630!
214
    rpcFreeCont(pMsg->pCont);
3,696,630✔
215
    taosFreeQitem(pMsg);
3,697,486✔
216
  }
217
}
3,606,457✔
218

219
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
1,236,516✔
220
  SVnodeObj *pVnode = pInfo->ahandle;
1,236,516✔
221
  SRpcMsg   *pMsg = NULL;
1,236,516✔
222

223
  for (int32_t i = 0; i < numOfMsgs; ++i) {
3,860,520✔
224
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
2,623,973!
225
    const STraceId *trace = &pMsg->info.traceId;
2,624,150✔
226
    dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
2,624,150!
227

228
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
2,624,150✔
229
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
2,624,020!
230
    rpcFreeCont(pMsg->pCont);
2,624,020✔
231
    taosFreeQitem(pMsg);
2,623,941✔
232
  }
233
}
1,236,547✔
234

235
static void vmSendResponse(SRpcMsg *pMsg) {
×
236
  if (pMsg->info.handle) {
×
237
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
238
    if (rpcSendResponse(&rsp) != 0) {
×
239
      dError("failed to send response since %s", terrstr());
×
240
    }
241
  }
242
}
×
243

244
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
9,724,636✔
245
  STfs *pTfs = pVnode->pImpl->pTfs;
9,724,636✔
246
  if (pTfs) {
9,724,636!
247
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
9,731,055✔
248
  } else {
249
    return osDataSpaceSufficient();
×
250
  }
251
}
252

253
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
23,472,422✔
254
  *pNode = vmAcquireVnode(pMgt, vgId);
23,472,422✔
255
  if (*pNode == NULL) {
23,517,578✔
256
    return terrno;
579,884✔
257
  }
258
  return 0;
22,937,694✔
259
}
260
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
23,473,229✔
261
  int32_t         code = 0;
23,473,229✔
262
  const STraceId *trace = &pMsg->info.traceId;
23,473,229✔
263
  if (pMsg->contLen < sizeof(SMsgHead)) {
23,473,229!
264
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
265
            pMsg->contLen);
266
    return TSDB_CODE_INVALID_MSG;
×
267
  }
268

269
  SMsgHead *pHead = pMsg->pCont;
23,473,229✔
270

271
  pHead->contLen = ntohl(pHead->contLen);
23,473,229✔
272
  pHead->vgId = ntohl(pHead->vgId);
23,473,229✔
273

274
  SVnodeObj *pVnode = NULL;
23,473,229✔
275
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
23,473,229✔
276
  if (code != 0) {
23,495,584✔
277
    dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
580,139!
278
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
279
    return code;
580,139✔
280
  }
281

282
  switch (qtype) {
22,915,445✔
283
    case QUERY_QUEUE:
4,951,526✔
284
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
4,951,526✔
285
      if (code) {
4,951,897✔
286
        dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
11!
287
      } else {
288
        dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
4,951,886!
289
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
4,951,886✔
290
      }
291
      break;
4,952,875✔
292
    case STREAM_QUEUE:
144,937✔
293
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
144,937!
294
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
144,937✔
295
      break;
144,945✔
296
    case STREAM_CTRL_QUEUE:
159,477✔
297
      dGTrace("vgId:%d, msg:%p put into vnode-stream-ctrl queue", pVnode->vgId, pMsg);
159,477!
298
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
159,477✔
299
      break;
159,681✔
300
    case STREAM_LONG_EXEC_QUEUE:
2,004✔
301
      dGTrace("vgId:%d, msg:%p put into vnode-stream-long-exec queue", pVnode->vgId, pMsg);
2,004!
302
      code = taosWriteQitem(pVnode->pStreamLongExecQ, pMsg);
2,004✔
303
      break;
2,004✔
304
    case FETCH_QUEUE:
3,689,766✔
305
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
3,689,766!
306
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
3,689,766✔
307
      break;
3,695,913✔
308
    case WRITE_QUEUE:
9,725,457✔
309
      if (!vmDataSpaceSufficient(pVnode)) {
9,725,457!
310
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
311
        dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
312
        break;
×
313
      }
314
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
9,738,943!
315
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
×
316
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
317
        break;
×
318
      }
319
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
9,735,808✔
320
        dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
236!
321
        code = TSDB_CODE_VND_STOPPED;
236✔
322
        break;
236✔
323
      }
324
      dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
9,735,572!
325
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
9,735,572✔
326
      break;
9,752,089✔
327
    case SYNC_QUEUE:
2,550,276✔
328
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
2,550,276!
329
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
2,550,276✔
330
      break;
2,553,425✔
331
    case SYNC_RD_QUEUE:
70,395✔
332
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
70,395!
333
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
70,395✔
334
      break;
70,389✔
335
    case APPLY_QUEUE:
1,607,054✔
336
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
1,607,054!
337
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
1,607,054✔
338
      break;
1,607,091✔
339
    default:
14,553✔
340
      code = TSDB_CODE_INVALID_MSG;
14,553✔
341
      break;
14,553✔
342
  }
343

344
  vmReleaseVnode(pMgmt, pVnode);
22,953,201✔
345
  return code;
22,939,467✔
346
}
347

348
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
70,732✔
349

350
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
2,335,475✔
351

352
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
9,703,386✔
353

354
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
5,456,714✔
355

356
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
3,690,528✔
357

358
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
872✔
359

360
int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CTRL_QUEUE); }
159,520✔
361

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

364
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
8,460✔
365
  const STraceId *trace = &pMsg->info.traceId;
8,460✔
366
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
8,460!
367
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
8,460✔
368
}
369

370
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
8,806✔
371
  const STraceId *trace = &pMsg->info.traceId;
8,806✔
372
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
8,806!
373
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
8,806✔
374
}
375

376
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
2,064,601✔
377
  int32_t code;
378
  if (pRpc->contLen < sizeof(SMsgHead)) {
2,064,601!
379
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
380
           pRpc->contLen);
381
    rpcFreeCont(pRpc->pCont);
×
382
    pRpc->pCont = NULL;
×
383
    return TSDB_CODE_INVALID_MSG;
×
384
  }
385

386
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
2,064,601✔
387
  SRpcMsg *pMsg;
388
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
2,064,601✔
389
  if (code) {
2,064,542!
390
    rpcFreeCont(pRpc->pCont);
×
391
    pRpc->pCont = NULL;
×
392
    return code;
×
393
  }
394

395
  SMsgHead *pHead = pRpc->pCont;
2,064,542✔
396
  dTrace("vgId:%d, msg:%p is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
2,064,542!
397

398
  pHead->contLen = htonl(pHead->contLen);
2,064,542✔
399
  pHead->vgId = htonl(pHead->vgId);
2,064,542✔
400
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
2,064,542✔
401
  pRpc->pCont = NULL;
2,064,542✔
402

403
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
2,064,542✔
404
  if (code != 0) {
2,064,616✔
405
    dTrace("msg:%p, is freed", pMsg);
4,015✔
406
    rpcFreeCont(pMsg->pCont);
4,015✔
407
    taosFreeQitem(pMsg);
4,014✔
408
  }
409

410
  return code;
2,064,608✔
411
}
412

413
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
149,770✔
414
  int32_t    size = -1;
149,770✔
415
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
149,770✔
416
  if (pVnode != NULL) {
149,779✔
417
    switch (qtype) {
128,007!
418
      case WRITE_QUEUE:
×
419
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
420
        break;
×
421
      case SYNC_QUEUE:
×
422
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
423
        break;
×
424
      case APPLY_QUEUE:
128,007✔
425
        size = taosQueueItemSize(pVnode->pApplyW.queue);
128,007✔
426
        break;
128,007✔
427
      case QUERY_QUEUE:
×
428
        size = taosQueueItemSize(pVnode->pQueryQ);
×
429
        break;
×
430
      case FETCH_QUEUE:
×
431
        size = taosQueueItemSize(pVnode->pFetchQ);
×
432
        break;
×
433
      case STREAM_QUEUE:
×
434
        size = taosQueueItemSize(pVnode->pStreamQ);
×
435
        break;
×
436
      case STREAM_CTRL_QUEUE:
×
437
        size = taosQueueItemSize(pVnode->pStreamCtrlQ);
×
438
        break;
×
439
      case STREAM_LONG_EXEC_QUEUE:
×
440
        size = taosQueueItemSize(pVnode->pStreamLongExecQ);
×
441
        break;
×
442
      default:
×
443
        break;
×
444
    }
445
  }
446
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
149,779✔
447
  if (size < 0) {
149,767✔
448
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
21,758✔
449
    size = 0;
21,765✔
450
  }
451
  return size;
149,774✔
452
}
453

454
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
10,691✔
455
  int32_t         code = 0;
10,691✔
456
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
10,691✔
457
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
10,691✔
458
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
10,691✔
459
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
10,691✔
460
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
10,691✔
461
  if (code) {
10,691!
462
    return code;
×
463
  }
464
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
10,691✔
465
  if (code) {
10,691!
466
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
467
    return code;
×
468
  }
469
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
10,691✔
470
  if (code) {
10,691!
471
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
472
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
473
    return code;
×
474
  }
475
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
10,691✔
476
  if (code) {
10,691!
477
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
478
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
479
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
480
    return code;
×
481
  }
482

483
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
10,691✔
484
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
10,691✔
485

486
  // init stream msg processing queue family
487
  pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue, 2);
10,691✔
488
  pVnode->pStreamCtrlQ = tWWorkerAllocQueue(&pMgmt->streamCtrlPool, pVnode, (FItems)vmProcessStreamCtrlQueue);
10,691✔
489
  pVnode->pStreamLongExecQ = tAutoQWorkerAllocQueue(&pMgmt->streamLongExecPool, pVnode, (FItem)vmProcessStreamLongExecQueue, 1);
10,691✔
490

491
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
10,691!
492
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
10,691!
493
      || pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL) {
10,691!
494
    return TSDB_CODE_OUT_OF_MEMORY;
×
495
  }
496

497
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
10,691!
498
        taosQueueGetThreadId(pVnode->pWriteW.queue));
499
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
10,691!
500
        taosQueueGetThreadId(pVnode->pSyncW.queue));
501
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
10,691!
502
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
503
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
10,691!
504
        taosQueueGetThreadId(pVnode->pApplyW.queue));
505
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
10,691!
506
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
10,691!
507
        taosQueueGetThreadId(pVnode->pFetchQ));
508
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
10,691!
509
  dInfo("vgId:%d, stream-long-exec-queue:%p is alloced", pVnode->vgId, pVnode->pStreamLongExecQ);
10,691!
510
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
10,691!
511
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
512
  return 0;
10,691✔
513
}
514

515
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
10,690✔
516
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
10,690✔
517
  tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
10,691✔
518
  tAutoQWorkerFreeQueue(&pMgmt->streamLongExecPool, pVnode->pStreamLongExecQ);
10,691✔
519
  tWWorkerFreeQueue(&pMgmt->streamCtrlPool, pVnode->pStreamCtrlQ);
10,691✔
520
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
10,690✔
521
  pVnode->pQueryQ = NULL;
10,691✔
522
  pVnode->pFetchQ = NULL;
10,691✔
523

524
  pVnode->pStreamQ = NULL;
10,691✔
525
  pVnode->pStreamCtrlQ = NULL;
10,691✔
526
  pVnode->pStreamLongExecQ = NULL;
10,691✔
527

528
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
10,691✔
529
}
10,691✔
530

531
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
2,102✔
532
  int32_t code = 0;
2,102✔
533

534
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
2,102✔
535
  pQPool->name = "vnode-query";
2,102✔
536
  pQPool->min = tsNumOfVnodeQueryThreads;
2,102✔
537
  pQPool->max = tsNumOfVnodeQueryThreads;
2,102✔
538
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
2,102!
539

540
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
2,102✔
541

542
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
2,102✔
543
  pStreamPool->name = "vnode-stream";
2,102✔
544
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
2,102✔
545
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
2,102!
546

547
  SAutoQWorkerPool *pLongExecPool = &pMgmt->streamLongExecPool;
2,102✔
548
  pLongExecPool->name = "vnode-stream-long-exec";
2,102✔
549
  pLongExecPool->ratio = tsRatioOfVnodeStreamThreads/3;
2,102✔
550
  if ((code = tAutoQWorkerInit(pLongExecPool)) != 0) return code;
2,102!
551

552
  SWWorkerPool *pStreamCtrlPool = &pMgmt->streamCtrlPool;
2,102✔
553
  pStreamCtrlPool->name = "vnode-stream-ctrl";
2,102✔
554
  pStreamCtrlPool->max = 1;
2,102✔
555
  if ((code = tWWorkerInit(pStreamCtrlPool)) != 0) return code;
2,102!
556

557
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
2,102✔
558
  pFPool->name = "vnode-fetch";
2,102✔
559
  pFPool->max = tsNumOfVnodeFetchThreads;
2,102✔
560
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
2,102!
561

562
  SSingleWorkerCfg mgmtCfg = {
2,102✔
563
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
564

565
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
2,102!
566

567
  int32_t threadNum = 0;
2,102✔
568
  if (tsNumOfCores == 1) {
2,102!
569
    threadNum = 2;
×
570
  } else {
571
    threadNum = tsNumOfCores;
2,102✔
572
  }
573
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
2,102✔
574
                                   .max = threadNum,
575
                                   .name = "vnode-multi-mgmt",
576
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
577
                                   .param = pMgmt};
578

579
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
2,102!
580

581
  dDebug("vnode workers are initialized");
2,102✔
582
  return 0;
2,102✔
583
}
584

585
void vmStopWorker(SVnodeMgmt *pMgmt) {
2,102✔
586
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
2,102✔
587
  tAutoQWorkerCleanup(&pMgmt->streamPool);
2,102✔
588
  tAutoQWorkerCleanup(&pMgmt->streamLongExecPool);
2,102✔
589
  tWWorkerCleanup(&pMgmt->streamCtrlPool);
2,102✔
590
  tWWorkerCleanup(&pMgmt->fetchPool);
2,102✔
591
  dDebug("vnode workers are closed");
2,102✔
592
}
2,102✔
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