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

taosdata / TDengine / #4476

08 Jul 2025 09:38AM UTC coverage: 62.948% (+0.03%) from 62.922%
#4476

push

travis-ci

web-flow
Merge pull request #31712 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

158623 of 321496 branches covered (49.34%)

Branch coverage included in aggregate %.

56 of 60 new or added lines in 13 files covered. (93.33%)

1176 existing lines in 42 files now uncovered.

245593 of 320647 relevant lines covered (76.59%)

23441503.11 hits per line

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

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

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

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

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

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

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

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

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

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

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

117
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
14,754,630!
118
  rpcFreeCont(pMsg->pCont);
14,754,630✔
119
  taosFreeQitem(pMsg);
14,761,806✔
120
}
14,762,123✔
121

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

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

136
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
428,453!
137
  rpcFreeCont(pMsg->pCont);
428,453✔
138
  taosFreeQitem(pMsg);
429,150✔
139
#endif
140
}
429,204✔
141

142
static void vmProcessStreamCtrlQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
165,989✔
143
#ifdef USE_STREAM
144
  SVnodeObj *pVnode = pInfo->ahandle;
165,989✔
145
  void      *pItem = NULL;
165,989✔
146
  int32_t    code = 0;
165,989✔
147

148
  while (1) {
185,218✔
149
    if (taosGetQitem(pQall, &pItem) == 0) {
351,207✔
150
      break;
166,099✔
151
    }
152

153
    SRpcMsg        *pMsg = pItem;
185,070✔
154
    const STraceId *trace = &pMsg->info.traceId;
185,070✔
155

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

165
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
185,102!
166
    rpcFreeCont(pMsg->pCont);
185,102✔
167
    taosFreeQitem(pMsg);
185,203✔
168
  }
169
#endif
170
}
166,099✔
171

172
static void vmProcessStreamChkptQueue(SQueueInfo *pInfo, STaosQall* pQall, int32_t numOfItems) {
12,994✔
173
  SVnodeObj *pVnode = pInfo->ahandle;
12,994✔
174
  void      *pItem = NULL;
12,994✔
175
  int32_t    code = 0;
12,994✔
176

177
  while (1) {
13,633✔
178
    if (taosGetQitem(pQall, &pItem) == 0) {
26,627✔
179
      break;
12,994✔
180
    }
181

182
    SRpcMsg        *pMsg = pItem;
13,633✔
183
    const STraceId *trace = &pMsg->info.traceId;
13,633✔
184

185
    dGTrace("vgId:%d, msg:%p, get from vnode-stream-chkpt queue", pVnode->vgId, pMsg);
13,633!
186
    code = vnodeProcessStreamChkptMsg(pVnode->pImpl, pMsg, pInfo);
13,633✔
187
    if (code != 0) {
13,633✔
188
      terrno = code;
16✔
189
      dGError("vgId:%d, msg:%p, failed to process stream chkpt msg %s since %s", pVnode->vgId, pMsg,
16!
190
              TMSG_INFO(pMsg->msgType), tstrerror(code));
191
      vmSendRsp(pMsg, code);
16✔
192
    }
193

194
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
13,633!
195
    rpcFreeCont(pMsg->pCont);
13,633✔
196
    taosFreeQitem(pMsg);
13,633✔
197
  }
198
}
12,994✔
199

200
static void vmProcessStreamLongExecQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
2,669✔
201
  SVnodeObj      *pVnode = pInfo->ahandle;
2,669✔
202
  const STraceId *trace = &pMsg->info.traceId;
2,669✔
203
  int32_t         code = 0;
2,669✔
204

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

207
  code = vnodeProcessStreamLongExecMsg(pVnode->pImpl, pMsg, pInfo);
2,669✔
208
  if (code != 0) {
2,667✔
209
    terrno = code;
1✔
210
    dGError("vgId:%d, msg:%p, failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
1!
211
            tstrerror(code));
212
    vmSendRsp(pMsg, code);
1✔
213
  }
214

215
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
2,667!
216
  rpcFreeCont(pMsg->pCont);
2,667✔
217
  taosFreeQitem(pMsg);
2,669✔
218
}
2,669✔
219

220
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
36,969,855✔
221
  SVnodeObj *pVnode = pInfo->ahandle;
36,969,855✔
222
  SRpcMsg   *pMsg = NULL;
36,969,855✔
223

224
  for (int32_t i = 0; i < numOfMsgs; ++i) {
75,088,993✔
225
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
38,092,127!
226
    const STraceId *trace = &pMsg->info.traceId;
38,099,090✔
227
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
38,099,090!
228

229
    terrno = 0;
38,099,091✔
230
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
38,081,857✔
231
    if (code != 0) {
38,093,387✔
232
      if (code == -1 && terrno != 0) {
4,043!
233
        code = terrno;
×
234
      }
235

236
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
4,043!
237
        dGDebug("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
×
238
      } else {
239
        dGError("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
4,043!
240
      }
241

242
      vmSendRsp(pMsg, code);
4,043✔
243
    }
244

245
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
38,093,387!
246
    rpcFreeCont(pMsg->pCont);
38,093,387✔
247
    taosFreeQitem(pMsg);
38,111,374✔
248
  }
249
}
36,996,866✔
250

251
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
4,242,637✔
252
  SVnodeObj *pVnode = pInfo->ahandle;
4,242,637✔
253
  SRpcMsg   *pMsg = NULL;
4,242,637✔
254

255
  for (int32_t i = 0; i < numOfMsgs; ++i) {
16,067,554✔
256
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
11,824,346!
257
    const STraceId *trace = &pMsg->info.traceId;
11,824,824✔
258
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
11,824,824!
259

260
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
11,824,824✔
261
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
11,824,347!
262
    rpcFreeCont(pMsg->pCont);
11,824,346✔
263
    taosFreeQitem(pMsg);
11,824,834✔
264
  }
265
}
4,243,208✔
266

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

276
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
19,420,266✔
277
  STfs *pTfs = pVnode->pImpl->pTfs;
19,420,266✔
278
  if (pTfs) {
19,420,266!
279
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
19,428,836✔
280
  } else {
281
    return osDataSpaceSufficient();
×
282
  }
283
}
284

285
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
90,795,723✔
286
  *pNode = vmAcquireVnode(pMgt, vgId);
90,795,723✔
287
  if (*pNode == NULL) {
90,967,186✔
288
    return terrno;
34,920✔
289
  }
290
  return 0;
90,932,266✔
291
}
292
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
90,810,751✔
293
  int32_t         code = 0;
90,810,751✔
294
  const STraceId *trace = &pMsg->info.traceId;
90,810,751✔
295
  if (pMsg->contLen < sizeof(SMsgHead)) {
90,810,751!
296
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
297
            pMsg->contLen);
298
    return TSDB_CODE_INVALID_MSG;
×
299
  }
300

301
  SMsgHead *pHead = pMsg->pCont;
90,810,751✔
302

303
  pHead->contLen = ntohl(pHead->contLen);
90,810,751✔
304
  pHead->vgId = ntohl(pHead->vgId);
90,810,751✔
305

306
  SVnodeObj *pVnode = NULL;
90,810,751✔
307
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
90,810,751✔
308
  if (code != 0) {
90,905,685✔
309
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
36,517!
310
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
311
    return code;
36,517✔
312
  }
313

314
  switch (qtype) {
90,869,168✔
315
    case QUERY_QUEUE:
14,749,963✔
316
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
14,749,963✔
317
      if (code) {
14,748,906✔
318
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
23!
319
      } else {
320
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
14,748,883!
321
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
14,748,883✔
322
      }
323
      break;
14,755,829✔
324
    case STREAM_QUEUE:
429,165✔
325
      dGTrace("vgId:%d, msg:%p, put into vnode-stream queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
429,165!
326
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
429,165✔
327
      break;
429,207✔
328
    case STREAM_CTRL_QUEUE:
184,183✔
329
      dGTrace("vgId:%d, msg:%p, put into vnode-stream-ctrl queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
184,183!
330
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
184,183✔
331
      break;
185,016✔
332
    case STREAM_LONG_EXEC_QUEUE:
2,667✔
333
      dGTrace("vgId:%d, msg:%p, put into vnode-stream-long-exec queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
2,667!
334
      code = taosWriteQitem(pVnode->pStreamLongExecQ, pMsg);
2,667✔
335
      break;
2,667✔
336
    case STREAM_CHKPT_QUEUE:
13,553✔
337
      dGTrace("vgId:%d, msg:%p, put into vnode-stream-chkpt queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
13,553!
338
      code = taosWriteQitem(pVnode->pStreamChkQ, pMsg);
13,553✔
339
      break;
13,610✔
340
    case FETCH_QUEUE:
38,057,039✔
341
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
38,057,039!
342
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
38,057,039✔
343
      break;
38,103,093✔
344
    case WRITE_QUEUE:
19,424,731✔
345
      if (!vmDataSpaceSufficient(pVnode)) {
19,424,731!
346
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
347
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
348
               tstrerror(code), TMSG_INFO(pMsg->msgType));
349
        break;
×
350
      }
351
#if 0
352
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
353
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
354
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
355
               tstrerror(code), TMSG_INFO(pMsg->msgType));
356
        break;
357
      }
358
#endif
359
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
19,439,744✔
360
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
668!
361
               TMSG_INFO(pMsg->msgType));
362
        code = TSDB_CODE_VND_STOPPED;
668✔
363
        break;
668✔
364
      }
365
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
19,439,076!
366
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
19,439,084✔
367
      break;
19,462,292✔
368
    case SYNC_QUEUE:
11,584,604✔
369
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
11,584,604!
370
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
11,584,622✔
371
      break;
11,598,129✔
372
    case SYNC_RD_QUEUE:
224,539✔
373
      dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
224,539!
374
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
224,538✔
375
      break;
224,790✔
376
    case APPLY_QUEUE:
6,156,565✔
377
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
6,156,565!
378
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
6,156,568✔
379
      break;
6,156,563✔
380
    default:
42,159✔
381
      code = TSDB_CODE_INVALID_MSG;
42,159✔
382
      break;
42,159✔
383
  }
384

385
  vmReleaseVnode(pMgmt, pVnode);
90,974,023✔
386
  return code;
90,953,483✔
387
}
388

389
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
224,992✔
390

391
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
11,111,680✔
392

393
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
19,391,078✔
394

395
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
13,933,751✔
396

397
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
38,067,677✔
398

399
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
1,066✔
400

401
int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CTRL_QUEUE); }
184,357✔
402

UNCOV
403
int32_t vmPutMsgToStreamLongExecQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_LONG_EXEC_QUEUE); }
×
404

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

407
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
13,595✔
408
  const STraceId *trace = &pMsg->info.traceId;
13,595✔
409
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
13,595!
410
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
13,595✔
411
}
412

413
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
15,483✔
414
  const STraceId *trace = &pMsg->info.traceId;
15,483✔
415
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
15,483!
416
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
15,483✔
417
}
418

419
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
7,941,405✔
420
  int32_t code;
421
  if (pRpc->contLen < sizeof(SMsgHead)) {
7,941,405!
UNCOV
422
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
423
           pRpc->contLen);
424
    rpcFreeCont(pRpc->pCont);
×
UNCOV
425
    pRpc->pCont = NULL;
×
426
    return TSDB_CODE_INVALID_MSG;
×
427
  }
428

429
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
7,941,405✔
430
  SRpcMsg *pMsg;
431
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
7,941,405✔
432
  if (code) {
7,941,467!
UNCOV
433
    rpcFreeCont(pRpc->pCont);
×
UNCOV
434
    pRpc->pCont = NULL;
×
435
    return code;
×
436
  }
437

438
  SMsgHead *pHead = pRpc->pCont;
7,941,467✔
439
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
7,941,467!
440

441
  pHead->contLen = htonl(pHead->contLen);
7,941,467✔
442
  pHead->vgId = htonl(pHead->vgId);
7,941,467✔
443
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
7,941,467✔
444
  pRpc->pCont = NULL;
7,941,467✔
445

446
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
7,941,467✔
447
  if (code != 0) {
7,941,526✔
448
    dTrace("msg:%p, is freed", pMsg);
6,684✔
449
    rpcFreeCont(pMsg->pCont);
6,684✔
450
    taosFreeQitem(pMsg);
6,682✔
451
  }
452

453
  return code;
7,941,508✔
454
}
455

456
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
4,854,858✔
457
  int32_t    size = -1;
4,854,858✔
458
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
4,854,858✔
459
  if (pVnode != NULL) {
4,854,968✔
460
    switch (qtype) {
4,820,668!
461
      case WRITE_QUEUE:
31,908✔
462
        size = taosQueueItemSize(pVnode->pWriteW.queue);
31,908✔
463
        break;
31,851✔
UNCOV
464
      case SYNC_QUEUE:
×
UNCOV
465
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
466
        break;
×
467
      case APPLY_QUEUE:
67,890✔
468
        size = taosQueueItemSize(pVnode->pApplyW.queue);
67,890✔
469
        break;
67,899✔
UNCOV
470
      case QUERY_QUEUE:
×
UNCOV
471
        size = taosQueueItemSize(pVnode->pQueryQ);
×
472
        break;
×
473
      case FETCH_QUEUE:
×
474
        size = taosQueueItemSize(pVnode->pFetchQ);
×
475
        break;
×
476
      case STREAM_QUEUE:
4,720,846✔
477
        size = taosQueueItemSize(pVnode->pStreamQ);
4,720,846✔
478
        break;
4,720,866✔
UNCOV
479
      case STREAM_CTRL_QUEUE:
×
UNCOV
480
        size = taosQueueItemSize(pVnode->pStreamCtrlQ);
×
481
        break;
×
482
      case STREAM_LONG_EXEC_QUEUE:
×
483
        size = taosQueueItemSize(pVnode->pStreamLongExecQ);
×
484
        break;
×
485
      case STREAM_CHKPT_QUEUE:
×
486
        size = taosQueueItemSize(pVnode->pStreamChkQ);
×
487
      default:
×
488
        break;
×
489
    }
490
  }
491
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
4,854,916✔
492
  if (size < 0) {
4,854,970✔
493
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
34,295✔
494
    size = 0;
34,293✔
495
  }
496
  return size;
4,854,968✔
497
}
498

499
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
17,005✔
500
  int32_t         code = 0;
17,005✔
501
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
17,005✔
502
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
17,005✔
503
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
17,005✔
504
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
17,005✔
505
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
17,005✔
506
  if (code) {
17,005!
UNCOV
507
    return code;
×
508
  }
509
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
17,005✔
510
  if (code) {
17,005!
UNCOV
511
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
UNCOV
512
    return code;
×
513
  }
514
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
17,005✔
515
  if (code) {
17,005!
UNCOV
516
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
UNCOV
517
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
518
    return code;
×
519
  }
520
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
17,005✔
521
  if (code) {
17,005!
UNCOV
522
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
UNCOV
523
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
524
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
525
    return code;
×
526
  }
527

528
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
17,005✔
529
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
17,005✔
530

531
  // init stream msg processing queue family
532
  pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue, 2);
17,005✔
533
  pVnode->pStreamCtrlQ = tWWorkerAllocQueue(&pMgmt->streamCtrlPool, pVnode, (FItems)vmProcessStreamCtrlQueue);
17,005✔
534
  pVnode->pStreamLongExecQ = tAutoQWorkerAllocQueue(&pMgmt->streamLongExecPool, pVnode, (FItem)vmProcessStreamLongExecQueue, 1);
17,005✔
535
  pVnode->pStreamChkQ = tWWorkerAllocQueue(&pMgmt->streamChkPool, pVnode, (FItems)vmProcessStreamChkptQueue);
17,005✔
536

537
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
17,005!
538
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
17,005!
539
      || pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL || pVnode->pStreamChkQ == NULL) {
17,005!
UNCOV
540
    return TSDB_CODE_OUT_OF_MEMORY;
×
541
  }
542

543
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
17,005!
544
        taosQueueGetThreadId(pVnode->pWriteW.queue));
545
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
17,005!
546
        taosQueueGetThreadId(pVnode->pSyncW.queue));
547
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
17,005!
548
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
549
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
17,005!
550
        taosQueueGetThreadId(pVnode->pApplyW.queue));
551
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
17,005!
552
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
17,005!
553
        taosQueueGetThreadId(pVnode->pFetchQ));
554
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
17,005!
555
  dInfo("vgId:%d, stream-long-exec-queue:%p is alloced", pVnode->vgId, pVnode->pStreamLongExecQ);
17,005!
556
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
17,005!
557
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
558
  dInfo("vgId:%d, stream-chk-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamChkQ,
17,005!
559
        taosQueueGetThreadId(pVnode->pStreamChkQ));
560
  return 0;
17,005✔
561
}
562

563
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
17,004✔
564
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
17,004✔
565
  tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
17,005✔
566
  tAutoQWorkerFreeQueue(&pMgmt->streamLongExecPool, pVnode->pStreamLongExecQ);
17,005✔
567
  tWWorkerFreeQueue(&pMgmt->streamCtrlPool, pVnode->pStreamCtrlQ);
17,004✔
568
  tWWorkerFreeQueue(&pMgmt->streamChkPool, pVnode->pStreamChkQ);
17,004✔
569
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
17,005✔
570
  pVnode->pQueryQ = NULL;
17,004✔
571
  pVnode->pFetchQ = NULL;
17,004✔
572

573
  pVnode->pStreamQ = NULL;
17,004✔
574
  pVnode->pStreamCtrlQ = NULL;
17,004✔
575
  pVnode->pStreamLongExecQ = NULL;
17,004✔
576

577
  pVnode->pStreamChkQ = NULL;
17,004✔
578
  pVnode->pFetchQ = NULL;
17,004✔
579
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
17,004✔
580
}
17,004✔
581

582
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
3,106✔
583
  int32_t code = 0;
3,106✔
584

585
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
3,106✔
586
  pQPool->name = "vnode-query";
3,106✔
587
  pQPool->min = tsNumOfVnodeQueryThreads;
3,106✔
588
  pQPool->max = tsNumOfVnodeQueryThreads;
3,106✔
589
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
3,106!
590

591
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
3,106✔
592

593
  SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
3,106✔
594
  pStreamPool->name = "vnode-stream";
3,106✔
595
  pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
3,106✔
596
  if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
3,106!
597

598
  SAutoQWorkerPool *pLongExecPool = &pMgmt->streamLongExecPool;
3,106✔
599
  pLongExecPool->name = "vnode-stream-long-exec";
3,106✔
600
  pLongExecPool->ratio = tsRatioOfVnodeStreamThreads/3;
3,106✔
601
  if ((code = tAutoQWorkerInit(pLongExecPool)) != 0) return code;
3,106!
602

603
  SWWorkerPool *pStreamCtrlPool = &pMgmt->streamCtrlPool;
3,106✔
604
  pStreamCtrlPool->name = "vnode-stream-ctrl";
3,106✔
605
  pStreamCtrlPool->max = 4;
3,106✔
606
  if ((code = tWWorkerInit(pStreamCtrlPool)) != 0) return code;
3,106!
607

608
  SWWorkerPool *pStreamChkPool = &pMgmt->streamChkPool;
3,106✔
609
  pStreamChkPool->name = "vnode-stream-chkpt";
3,106✔
610
  pStreamChkPool->max = 1;
3,106✔
611
  if ((code = tWWorkerInit(pStreamChkPool)) != 0) return code;
3,106!
612

613
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
3,106✔
614
  pFPool->name = "vnode-fetch";
3,106✔
615
  pFPool->max = tsNumOfVnodeFetchThreads;
3,106✔
616
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
3,106!
617

618
  SSingleWorkerCfg mgmtCfg = {
3,106✔
619
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
620

621
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
3,106!
622

623
  int32_t threadNum = 0;
3,106✔
624
  if (tsNumOfCores == 1) {
3,106!
UNCOV
625
    threadNum = 2;
×
626
  } else {
627
    threadNum = tsNumOfCores;
3,106✔
628
  }
629
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
3,106✔
630
                                   .max = threadNum,
631
                                   .name = "vnode-multi-mgmt",
632
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
633
                                   .param = pMgmt};
634

635
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
3,106!
636

637
  dDebug("vnode workers are initialized");
3,106✔
638
  return 0;
3,106✔
639
}
640

641
void vmStopWorker(SVnodeMgmt *pMgmt) {
3,106✔
642
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
3,106✔
643
  tAutoQWorkerCleanup(&pMgmt->streamPool);
3,106✔
644
  tAutoQWorkerCleanup(&pMgmt->streamLongExecPool);
3,106✔
645
  tWWorkerCleanup(&pMgmt->streamCtrlPool);
3,106✔
646
  tWWorkerCleanup(&pMgmt->streamChkPool);
3,106✔
647
  tWWorkerCleanup(&pMgmt->fetchPool);
3,106✔
648
  dDebug("vnode workers are closed");
3,106✔
649
}
3,106✔
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