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

taosdata / TDengine / #3649

13 Mar 2025 05:26AM UTC coverage: 50.655% (+10.8%) from 39.825%
#3649

push

travis-ci

web-flow
Merge pull request #30158 from taosdata/docs/anchor-caps-30

docs: lowercase anchors for 3.0

109900 of 288393 branches covered (38.11%)

Branch coverage included in aggregate %.

180720 of 285331 relevant lines covered (63.34%)

1991725.06 hits per line

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

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

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

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

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

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

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

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

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

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

109
  dGTrace("vgId:%d, msg:%p get from vnode-query queue", pVnode->vgId, pMsg);
32,008!
110
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
32,008✔
111
  if (code != 0) {
32,008!
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);
32,008!
118
  rpcFreeCont(pMsg->pCont);
32,008✔
119
  taosFreeQitem(pMsg);
32,008✔
120
}
32,008✔
121

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

126
  dGTrace("vgId:%d, msg:%p get from vnode-stream queue", pVnode->vgId, pMsg);
20,143!
127
  int32_t code = vnodeProcessStreamMsg(pVnode->pImpl, pMsg, pInfo);
20,143✔
128
  if (code != 0) {
20,142!
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);
20,142!
136
  rpcFreeCont(pMsg->pCont);
20,142✔
137
  taosFreeQitem(pMsg);
20,139✔
138
}
20,140✔
139

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

145
  while (1) {
4,623✔
146
    if (taosGetQitem(pQall, &pItem) == 0) {
8,830✔
147
      break;
4,207✔
148
    }
149

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

153
    dGTrace("vgId:%d, msg:%p get from vnode-stream-ctrl queue", pVnode->vgId, pMsg);
4,623!
154
    code = vnodeProcessStreamCtrlMsg(pVnode->pImpl, pMsg, pInfo);
4,623✔
155
    if (code != 0) {
4,623!
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);
4,623!
163
    rpcFreeCont(pMsg->pCont);
4,623✔
164
    taosFreeQitem(pMsg);
4,623✔
165
  }
166
}
4,207✔
167

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

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

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

181
    dGTrace("vgId:%d, msg:%p get from vnode-stream-chkpt queue", pVnode->vgId, pMsg);
69!
182
    code = vnodeProcessStreamChkptMsg(pVnode->pImpl, pMsg, pInfo);
69✔
183
    if (code != 0) {
69!
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);
69!
191
    rpcFreeCont(pMsg->pCont);
69✔
192
    taosFreeQitem(pMsg);
69✔
193
  }
194
}
68✔
195

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

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

203
  code = vnodeProcessStreamLongExecMsg(pVnode->pImpl, pMsg, pInfo);
17✔
204
  if (code != 0) {
17!
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);
17!
212
  rpcFreeCont(pMsg->pCont);
17✔
213
  taosFreeQitem(pMsg);
17✔
214
}
17✔
215

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

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

225
    terrno = 0;
103,167✔
226
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
103,139✔
227
    if (code != 0) {
103,176!
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);
103,176!
242
    rpcFreeCont(pMsg->pCont);
103,176✔
243
    taosFreeQitem(pMsg);
103,173✔
244
  }
245
}
102,420✔
246

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

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

256
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
311,631✔
257
    dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
311,616!
258
    rpcFreeCont(pMsg->pCont);
311,616✔
259
    taosFreeQitem(pMsg);
311,597✔
260
  }
261
}
254,441✔
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) {
415,764✔
273
  STfs *pTfs = pVnode->pImpl->pTfs;
415,764✔
274
  if (pTfs) {
415,764!
275
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
415,764✔
276
  } else {
277
    return osDataSpaceSufficient();
×
278
  }
279
}
280

281
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
1,242,908✔
282
  *pNode = vmAcquireVnode(pMgt, vgId);
1,242,908✔
283
  if (*pNode == NULL) {
1,243,208✔
284
    return terrno;
1,194✔
285
  }
286
  return 0;
1,242,014✔
287
}
288
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
1,242,941✔
289
  int32_t         code = 0;
1,242,941✔
290
  const STraceId *trace = &pMsg->info.traceId;
1,242,941✔
291
  if (pMsg->contLen < sizeof(SMsgHead)) {
1,242,941!
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;
1,242,941✔
298

299
  pHead->contLen = ntohl(pHead->contLen);
1,242,941✔
300
  pHead->vgId = ntohl(pHead->vgId);
1,242,941✔
301

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

310
  switch (qtype) {
1,241,990!
311
    case QUERY_QUEUE:
32,006✔
312
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
32,006✔
313
      if (code) {
32,007!
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);
32,007!
317
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
32,007✔
318
      }
319
      break;
32,007✔
320
    case STREAM_QUEUE:
20,143✔
321
      dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
20,143!
322
      code = taosWriteQitem(pVnode->pStreamQ, pMsg);
20,143✔
323
      break;
20,141✔
324
    case STREAM_CTRL_QUEUE:
4,621✔
325
      dGTrace("vgId:%d, msg:%p put into vnode-stream-ctrl queue", pVnode->vgId, pMsg);
4,621!
326
      code = taosWriteQitem(pVnode->pStreamCtrlQ, pMsg);
4,621✔
327
      break;
4,623✔
328
    case STREAM_LONG_EXEC_QUEUE:
17✔
329
      dGTrace("vgId:%d, msg:%p put into vnode-stream-long-exec queue", pVnode->vgId, pMsg);
17!
330
      code = taosWriteQitem(pVnode->pStreamLongExecQ, pMsg);
17✔
331
      break;
17✔
332
    case STREAM_CHKPT_QUEUE:
69✔
333
      dGTrace("vgId:%d, msg:%p put into vnode-stream-chkpt queue", pVnode->vgId, pMsg);
69!
334
      code = taosWriteQitem(pVnode->pStreamChkQ, pMsg);
69✔
335
      break;
69✔
336
    case FETCH_QUEUE:
103,167✔
337
      dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
103,167!
338
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
103,167✔
339
      break;
103,169✔
340
    case WRITE_QUEUE:
415,768✔
341
      if (!vmDataSpaceSufficient(pVnode)) {
415,768!
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)) {
415,762!
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) {
415,761!
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);
415,761!
357
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
415,761✔
358
      break;
415,753✔
359
    case SYNC_QUEUE:
299,232✔
360
      dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
299,232!
361
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
299,232✔
362
      break;
299,226✔
363
    case SYNC_RD_QUEUE:
12,387✔
364
      dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
12,387!
365
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
12,387✔
366
      break;
12,388✔
367
    case APPLY_QUEUE:
354,623✔
368
      dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
354,623!
369
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
354,623✔
370
      break;
354,524✔
371
    default:
×
372
      code = TSDB_CODE_INVALID_MSG;
×
373
      break;
×
374
  }
375

376
  vmReleaseVnode(pMgmt, pVnode);
1,241,874✔
377
  return code;
1,242,053✔
378
}
379

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

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

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

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

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

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

392
int32_t vmPutMsgToStreamCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_CTRL_QUEUE); }
4,623✔
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) {
1,751✔
399
  const STraceId *trace = &pMsg->info.traceId;
1,751✔
400
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
1,751!
401
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
1,751✔
402
}
403

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

410
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
444,254✔
411
  int32_t code;
412
  if (pRpc->contLen < sizeof(SMsgHead)) {
444,254!
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;
444,254✔
421
  SRpcMsg *pMsg;
422
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
444,254✔
423
  if (code) {
444,231!
424
    rpcFreeCont(pRpc->pCont);
×
425
    pRpc->pCont = NULL;
×
426
    return code;
×
427
  }
428

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

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

437
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
444,231✔
438
  if (code != 0) {
444,432✔
439
    dTrace("msg:%p, is freed", pMsg);
935✔
440
    rpcFreeCont(pMsg->pCont);
935✔
441
    taosFreeQitem(pMsg);
933✔
442
  }
443

444
  return code;
444,431✔
445
}
446

447
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
16,203✔
448
  int32_t    size = -1;
16,203✔
449
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
16,203✔
450
  if (pVnode != NULL) {
16,205✔
451
    switch (qtype) {
10,638!
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:
10,638✔
459
        size = taosQueueItemSize(pVnode->pApplyW.queue);
10,638✔
460
        break;
10,638✔
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);
16,205✔
483
  if (size < 0) {
16,202✔
484
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
5,564!
485
    size = 0;
5,565✔
486
  }
487
  return size;
16,203✔
488
}
489

490
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
2,926✔
491
  int32_t         code = 0;
2,926✔
492
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
2,926✔
493
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
2,926✔
494
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
2,926✔
495
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
2,926✔
496
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
2,926✔
497
  if (code) {
2,926!
498
    return code;
×
499
  }
500
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
2,926✔
501
  if (code) {
2,926!
502
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
503
    return code;
×
504
  }
505
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
2,926✔
506
  if (code) {
2,926!
507
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
508
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
509
    return code;
×
510
  }
511
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
2,926✔
512
  if (code) {
2,926!
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);
2,926✔
520
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
2,926✔
521

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

528
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
2,926!
529
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL
2,926!
530
      || pVnode->pStreamCtrlQ == NULL || pVnode->pStreamLongExecQ == NULL || pVnode->pStreamChkQ == NULL) {
2,926!
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,
2,926!
535
        taosQueueGetThreadId(pVnode->pWriteW.queue));
536
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
2,926!
537
        taosQueueGetThreadId(pVnode->pSyncW.queue));
538
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
2,926!
539
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
540
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
2,926!
541
        taosQueueGetThreadId(pVnode->pApplyW.queue));
542
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
2,926!
543
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
2,926!
544
        taosQueueGetThreadId(pVnode->pFetchQ));
545
  dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
2,926!
546
  dInfo("vgId:%d, stream-long-exec-queue:%p is alloced", pVnode->vgId, pVnode->pStreamLongExecQ);
2,926!
547
  dInfo("vgId:%d, stream-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamCtrlQ,
2,926!
548
        taosQueueGetThreadId(pVnode->pStreamCtrlQ));
549
  dInfo("vgId:%d, stream-chk-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pStreamChkQ,
2,926!
550
        taosQueueGetThreadId(pVnode->pStreamChkQ));
551
  return 0;
2,926✔
552
}
553

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

564
  pVnode->pStreamQ = NULL;
2,802✔
565
  pVnode->pStreamCtrlQ = NULL;
2,802✔
566
  pVnode->pStreamLongExecQ = NULL;
2,802✔
567

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

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

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

582
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
580✔
583

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

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

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

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

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

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

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

614
  int32_t threadNum = 0;
580✔
615
  if (tsNumOfCores == 1) {
580!
616
    threadNum = 2;
×
617
  } else {
618
    threadNum = tsNumOfCores;
580✔
619
  }
620
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
580✔
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;
580!
627

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

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