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

taosdata / TDengine / #5054

13 May 2026 12:00PM UTC coverage: 73.358% (-0.04%) from 73.397%
#5054

push

travis-ci

web-flow
feat: taosdump support stream backup/restore (#35326)

139 of 170 new or added lines in 3 files covered. (81.76%)

771 existing lines in 142 files now uncovered.

281543 of 383795 relevant lines covered (73.36%)

133389099.84 hits per line

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

82.31
/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) {
14,668,902✔
21
  if (pMsg->info.handle == NULL) return;
14,668,902✔
22
  SRpcMsg rsp = {
29,333,940✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
14,669,286✔
25
      .contLen = pMsg->info.rspLen,
14,669,676✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
14,669,676✔
29
}
30

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
3,764,122✔
37
  switch (pMsg->msgType) {
3,764,122✔
38
    case TDMT_DND_CREATE_VNODE:
3,761,061✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
3,761,061✔
40
      break;
3,761,245✔
41
#ifdef USE_MOUNT
42
    case TDMT_DND_RETRIEVE_MOUNT_PATH:
1,341✔
43
      code = vmProcessRetrieveMountPathReq(pMgmt, pMsg);
1,341✔
44
      break;
1,341✔
45
    case TDMT_DND_MOUNT_VNODE:
1,536✔
46
      code = vmProcessMountVnodeReq(pMgmt, pMsg);
1,536✔
47
      break;
1,536✔
48
#endif
49
  }
50

51
  if (IsReq(pMsg)) {
3,764,306✔
52
    if (code != 0) {
3,764,122✔
53
      if (terrno != 0) code = terrno;
957✔
54
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
957✔
55
    }
56
    vmSendRsp(pMsg, code);
3,764,122✔
57
  }
58

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
3,763,653✔
60
  rpcFreeCont(pMsg->pCont);
3,763,653✔
61
  taosFreeQitem(pMsg);
3,764,122✔
62
}
3,763,299✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
5,438,346✔
70
  switch (pMsg->msgType) {
5,438,346✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
1,985,577✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
1,985,577✔
76
      break;
1,985,577✔
77
    case TDMT_VND_ALTER_REPLICA:
768,356✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
768,356✔
79
      break;
768,356✔
80
    case TDMT_VND_DISABLE_WRITE:
30,177✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
30,177✔
82
      break;
30,177✔
83
    case TDMT_VND_SET_KEEP_VERSION:
3,718✔
84
      code = vmProcessSetKeepVersionReq(pMgmt, pMsg);
3,718✔
85
      break;
3,718✔
86
    case TDMT_VND_ALTER_HASHRANGE:
29,373✔
87
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
29,373✔
88
      break;
29,373✔
89
    case TDMT_DND_ALTER_VNODE_TYPE:
2,319,402✔
90
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
2,319,402✔
91
      break;
2,319,402✔
92
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
93
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
94
      break;
×
95
    case TDMT_VND_ARB_HEARTBEAT:
129,742✔
96
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
129,742✔
97
      break;
129,742✔
98
    case TDMT_VND_ALTER_ELECTBASELINE:
32,696✔
99
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
32,696✔
100
      break;
32,696✔
101
    case TDMT_DND_QUERY_COMPACT_PROGRESS:
139,305✔
102
      code = vmProcessDnodeQueryCompactProgressReq(pMgmt, pMsg);
139,305✔
103
      break;
139,305✔
104
    default:
×
105
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
106
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
107
  }
108

109
  if (IsReq(pMsg)) {
5,438,346✔
110
    if (code != 0) {
5,438,346✔
111
      if (terrno != 0) code = terrno;
2,209,956✔
112
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
2,209,956✔
113
    }
114
    vmSendRsp(pMsg, code);
5,438,346✔
115
  }
116

117
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
5,438,346✔
118
  rpcFreeCont(pMsg->pCont);
5,438,346✔
119
  taosFreeQitem(pMsg);
5,438,346✔
120
}
5,438,346✔
121

122
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
805,798,999✔
123
  SVnodeObj      *pVnode = pInfo->ahandle;
805,798,999✔
124
  const STraceId *trace = &pMsg->info.traceId;
805,808,850✔
125

126
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
805,807,787✔
127
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
805,807,965✔
128
  if (code != 0) {
805,727,469✔
129
    if (terrno != 0) code = terrno;
4,602,593✔
130
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
4,602,593✔
131
    vmSendRsp(pMsg, code);
4,602,593✔
132
  }
133

134
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
805,727,469✔
135
  rpcFreeCont(pMsg->pCont);
805,727,469✔
136
  taosFreeQitem(pMsg);
805,729,698✔
137
}
805,685,163✔
138

139
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
1,172,358,197✔
140
  SVnodeObj *pVnode = pInfo->ahandle;
1,172,358,197✔
141
  SRpcMsg   *pMsg = NULL;
1,172,379,582✔
142

143
  for (int32_t i = 0; i < numOfMsgs; ++i) {
2,147,483,647✔
144
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
1,214,162,053✔
145
    const STraceId *trace = &pMsg->info.traceId;
1,214,097,401✔
146
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
1,214,212,059✔
147

148
    terrno = 0;
1,214,214,696✔
149
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
1,214,196,928✔
150
    if (code != 0) {
1,214,227,535✔
151
      if (code == -1 && terrno != 0) {
864,615✔
152
        code = terrno;
×
153
      }
154

155
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
864,615✔
156
        dGDebug("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
×
157
      } else {
158
        dGError("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
864,615✔
159
      }
160

161
      vmSendRsp(pMsg, code);
864,615✔
162
    }
163

164
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
1,214,227,535✔
165
    rpcFreeCont(pMsg->pCont);
1,214,227,535✔
166
    taosFreeQitem(pMsg);
1,214,205,316✔
167
  }
168
}
1,172,405,721✔
169

170
static void vmProcessStreamReaderQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
26,970,350✔
171
  SVnodeObj *pVnode = pInfo->ahandle;
26,970,350✔
172
  const STraceId *trace = &pMsg->info.traceId;
26,970,948✔
173
  dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
26,970,427✔
174

175
  terrno = 0;
26,970,427✔
176
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg, pInfo);
26,971,530✔
177
  if (code != 0) {
26,962,538✔
178
    if (code == -1 && terrno != 0) {
160,550✔
179
      code = terrno;
×
180
    }
181

182
    if (code == 0) {
160,550✔
183
      dGDebug("vgId:%d, msg:%p, success to stream reader since %s [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, terrstr());
×
184
    } else {
185
      dGError("vgId:%d, msg:%p, failed to stream reader since %s [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, terrstr());
160,550✔
186
    }
187
  }
188

189
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
26,962,538✔
190
  rpcFreeCont(pMsg->pCont);
26,962,538✔
191
  taosFreeQitem(pMsg);
26,964,348✔
192
}
26,962,511✔
193

194
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
641,462,386✔
195
  SVnodeObj *pVnode = pInfo->ahandle;
641,462,386✔
196
  SRpcMsg   *pMsg = NULL;
641,465,606✔
197

198
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,953,773,573✔
199
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
1,312,335,312✔
200
    const STraceId *trace = &pMsg->info.traceId;
1,312,325,137✔
201
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
1,312,338,385✔
202

203
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
1,312,338,385✔
204
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,312,327,883✔
205
    rpcFreeCont(pMsg->pCont);
1,312,329,033✔
206
    taosFreeQitem(pMsg);
1,312,301,071✔
207
  }
208
}
641,443,907✔
209

210
static void vmSendResponse(SRpcMsg *pMsg) {
×
211
  if (pMsg->info.handle) {
×
212
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
213
    if (rpcSendResponse(&rsp) != 0) {
×
214
      dError("failed to send response since %s", terrstr());
×
215
    }
216
  }
217
}
×
218

219
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
887,624,287✔
220
  STfs *pTfs = pVnode->pImpl->pTfs;
887,624,287✔
221
  if (pTfs) {
887,647,616✔
222
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
887,647,616✔
223
  } else {
224
    return osDataSpaceSufficient();
×
225
  }
226
}
227

228
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
2,147,483,647✔
229
  *pNode = vmAcquireVnode(pMgt, vgId);
2,147,483,647✔
230
  if (*pNode == NULL) {
2,147,483,647✔
231
    return terrno;
16,552,746✔
232
  }
233
  return 0;
2,147,483,647✔
234
}
235
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
2,147,483,647✔
236
  int32_t         code = 0;
2,147,483,647✔
237
  SMsgHead *      pHead = pMsg->pCont;
2,147,483,647✔
238
  SVnodeObj *     pVnode = NULL;
2,147,483,647✔
239
  const STraceId *trace = &pMsg->info.traceId;
2,147,483,647✔
240

241
  if (pMsg->contLen < sizeof(SMsgHead)) {
2,147,483,647✔
242
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
243
            pMsg->contLen);
244
    return TSDB_CODE_INVALID_MSG;
×
245
  }
246

247
  pHead->contLen = ntohl(pHead->contLen);
2,147,483,647✔
248
  pHead->vgId = ntohl(pHead->vgId);
2,147,483,647✔
249
  
250
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
2,147,483,647✔
251
  if (code != 0) {
2,147,483,647✔
252
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
16,552,746✔
253
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
254
    return code;
16,552,746✔
255
  }
256

257
  switch (qtype) {
2,147,483,647✔
258
    case QUERY_QUEUE:
805,673,661✔
259
      // let's put into different query processing queue. The query type is extracted during preprocessing procedure,
260
      // mquery-queue for meta info query, and query-queue for ordinary users' queries.
261
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
805,673,661✔
262
      if (code) {
805,665,245✔
263
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
264
      } else {
265
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
805,665,245✔
266
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
805,665,423✔
267
      }
268
      break;
805,738,311✔
269
    case FETCH_QUEUE:
1,213,930,532✔
270
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,213,930,532✔
271
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
1,213,930,532✔
272
      break;
1,214,238,086✔
273
    case WRITE_QUEUE:
887,617,032✔
274
      if (!vmDataSpaceSufficient(pVnode)) {
887,617,032✔
275
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
276
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
277
               tstrerror(code), TMSG_INFO(pMsg->msgType));
278
        break;
×
279
      }
280
#if 0
281
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
282
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
284
               tstrerror(code), TMSG_INFO(pMsg->msgType));
285
        break;
286
      }
287
#endif
288
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
887,634,404✔
289
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
122,095✔
290
               TMSG_INFO(pMsg->msgType));
291
        code = TSDB_CODE_VND_STOPPED;
122,095✔
292
        break;
122,095✔
293
      }
294
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
887,489,039✔
295
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
887,490,195✔
296
      break;
887,539,195✔
297
    case SYNC_QUEUE:
1,254,696,661✔
298
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,254,696,661✔
299
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
1,254,696,661✔
300
      break;
1,254,840,911✔
301
    case SYNC_RD_QUEUE:
57,476,055✔
302
      if(tsSyncLogHeartbeat){
57,476,055✔
303
        dGInfo("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
×
304
      }
305
      else{
306
        dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
57,476,055✔
307
      }
308
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
57,476,055✔
309
      break;
57,488,047✔
310
    case APPLY_QUEUE:
723,531,624✔
311
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
723,531,624✔
312
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
723,531,624✔
313
      break;
723,533,909✔
314
    case STREAM_READER_QUEUE:
26,963,891✔
315
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
26,963,891✔
316
              TMSG_INFO(pMsg->msgType));
317
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
26,964,121✔
318
      break;
26,969,565✔
UNCOV
319
    default:
×
UNCOV
320
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
321
      break;
×
322
  }
323

324
  vmReleaseVnode(pMgmt, pVnode);
2,147,483,647✔
325
  return code;
2,147,483,647✔
326
}
327

328
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
57,826,438✔
329

330
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
1,034,328,644✔
331

332
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
886,489,121✔
333

334
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
760,356,690✔
335

336
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
1,214,168,154✔
337

338
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
26,991,317✔
339

340
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
3,755,234✔
341
  const STraceId *trace = &pMsg->info.traceId;
3,755,234✔
342
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
3,762,939✔
343
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
3,762,939✔
344
}
345

346
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
5,438,346✔
347
  const STraceId *trace = &pMsg->info.traceId;
5,438,346✔
348
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
5,438,346✔
349
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
5,438,346✔
350
}
351

352
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
1,006,572,286✔
353
  int32_t code;
354
  if (pRpc->contLen < sizeof(SMsgHead)) {
1,006,572,286✔
355
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
356
           pRpc->contLen);
357
    rpcFreeCont(pRpc->pCont);
×
358
    pRpc->pCont = NULL;
×
359
    return TSDB_CODE_INVALID_MSG;
×
360
  }
361

362
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
1,006,579,651✔
363
  SRpcMsg *pMsg;
1,006,571,432✔
364
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
1,006,576,052✔
365
  if (code) {
1,006,559,699✔
366
    rpcFreeCont(pRpc->pCont);
×
367
    pRpc->pCont = NULL;
×
368
    return code;
×
369
  }
370

371
  SMsgHead *pHead = pRpc->pCont;
1,006,559,699✔
372
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
1,006,562,005✔
373

374
  pHead->contLen = htonl(pHead->contLen);
1,006,562,005✔
375
  pHead->vgId = htonl(pHead->vgId);
1,006,561,300✔
376
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
1,006,556,082✔
377
  pRpc->pCont = NULL;
1,006,556,082✔
378

379
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
1,006,574,898✔
380
  if (code != 0) {
1,006,578,318✔
381
    dTrace("msg:%p, is freed", pMsg);
1,709,471✔
382
    rpcFreeCont(pMsg->pCont);
1,709,471✔
383
    taosFreeQitem(pMsg);
1,709,471✔
384
  }
385

386
  return code;
1,006,573,764✔
387
}
388

389
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
21,869,109✔
390
  int32_t    size = -1;
21,869,109✔
391
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
21,869,109✔
392
  if (pVnode != NULL) {
21,875,038✔
393
    switch (qtype) {
11,782,990✔
394
      case WRITE_QUEUE:
×
395
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
396
        break;
×
397
      case SYNC_QUEUE:
×
398
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
399
        break;
×
400
      case APPLY_QUEUE:
11,782,990✔
401
        size = taosQueueItemSize(pVnode->pApplyW.queue);
11,782,990✔
402
        break;
11,784,664✔
403
      case QUERY_QUEUE:
×
404
        size = taosQueueItemSize(pVnode->pQueryQ);
×
405
        break;
×
406
      case FETCH_QUEUE:
×
407
        size = taosQueueItemSize(pVnode->pFetchQ);
×
408
        break;
×
409
      case STREAM_READER_QUEUE:
×
410
        size = taosQueueItemSize(pVnode->pStreamReaderQ);
×
411
        break;
×
412
      default:
×
413
        break;
×
414
    }
415
  }
416
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
21,876,712✔
417
  if (size < 0) {
21,869,026✔
418
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
10,085,658✔
419
    size = 0;
10,085,292✔
420
  }
421
  return size;
21,868,660✔
422
}
423

424
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
5,050,303✔
425
  int32_t         code = 0;
5,050,303✔
426
  SMultiWorkerCfg wcfg = {.max = 1,
5,050,303✔
427
                          .name = "vnode-write",
428
                          .fp = (FItems)vnodeProposeWriteMsg,
429
                          .param = pVnode->pImpl,
5,050,598✔
430
                          .threadCategory = THREAD_CAT_WRITE};
431
  SMultiWorkerCfg scfg = {.max = 1,
5,051,593✔
432
                          .name = "vnode-sync",
433
                          .fp = (FItems)vmProcessSyncQueue,
434
                          .param = pVnode,
435
                          .threadCategory = THREAD_CAT_WRITE};
436
  SMultiWorkerCfg sccfg = {.max = 1,
5,048,758✔
437
                           .name = "vnode-sync-rd",
438
                           .fp = (FItems)vmProcessSyncQueue,
439
                           .param = pVnode,
440
                           .threadCategory = THREAD_CAT_WRITE};
441
  SMultiWorkerCfg acfg = {.max = 1,
5,047,763✔
442
                          .name = "vnode-apply",
443
                          .fp = (FItems)vnodeApplyWriteMsg,
444
                          .param = pVnode->pImpl,
5,048,852✔
445
                          .threadCategory = THREAD_CAT_WRITE};
446
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
5,050,850✔
447
  if (code) {
5,052,008✔
448
    return code;
×
449
  }
450
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
5,052,008✔
451
  if (code) {
5,052,008✔
452
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
453
    return code;
×
454
  }
455
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
5,052,008✔
456
  if (code) {
5,052,008✔
457
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
458
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
459
    return code;
×
460
  }
461
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
5,052,008✔
462
  if (code) {
5,052,008✔
463
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
464
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
465
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
466
    return code;
×
467
  }
468

469
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
5,052,008✔
470
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
5,052,008✔
471
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
5,052,008✔
472

473
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
5,052,008✔
474
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
5,052,008✔
475
    return TSDB_CODE_OUT_OF_MEMORY;
×
476
  }
477

478
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
5,052,008✔
479
        taosQueueGetThreadId(pVnode->pWriteW.queue));
480
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
5,052,008✔
481
        taosQueueGetThreadId(pVnode->pSyncW.queue));
482
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
5,052,008✔
483
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
484
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
5,052,008✔
485
        taosQueueGetThreadId(pVnode->pApplyW.queue));
486
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
5,052,008✔
487
  dInfo("vgId:%d, stream-reader-queue:%p is alloced", pVnode->vgId, pVnode->pStreamReaderQ);
5,052,008✔
488
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
5,052,008✔
489
        taosQueueGetThreadId(pVnode->pFetchQ));
490
  return 0;
5,052,008✔
491
}
492

493
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
5,052,008✔
494
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
5,052,008✔
495
  tQueryAutoQWorkerFreeQueue(&pMgmt->streamReaderPool, pVnode->pStreamReaderQ);
5,052,008✔
496
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
5,052,008✔
497

498
  pVnode->pQueryQ = NULL;
5,052,008✔
499
  pVnode->pFetchQ = NULL;
5,052,008✔
500
  pVnode->pStreamReaderQ = NULL;
5,052,008✔
501
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
5,052,008✔
502
}
5,052,008✔
503

504
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
745,825✔
505
  int32_t code = 0;
745,825✔
506

507
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
745,825✔
508
  pQPool->name = "vnode-query";
745,825✔
509
  pQPool->min = tsNumOfVnodeQueryThreads;
745,825✔
510
  pQPool->max = tsNumOfVnodeQueryThreads;
745,825✔
511
  pQPool->threadCategory = THREAD_CAT_READ;
745,825✔
512
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
745,825✔
513

514
  SQueryAutoQWorkerPool *pSPool = &pMgmt->streamReaderPool;
745,825✔
515
  pSPool->name = "vnode-st-reader";
745,825✔
516
  pSPool->min = tsNumOfVnodeStreamReaderThreads;
745,825✔
517
  pSPool->max = tsNumOfVnodeStreamReaderThreads;
745,825✔
518
  pSPool->threadCategory = THREAD_CAT_READ;
745,825✔
519
  if ((code = tQueryAutoQWorkerInit(pSPool)) != 0) return code;
745,825✔
520

521
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
745,825✔
522

523
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
745,825✔
524
  pFPool->name = "vnode-fetch";
745,825✔
525
  pFPool->max = tsNumOfVnodeFetchThreads;
745,825✔
526
  pFPool->threadCategory = THREAD_CAT_READ;
745,825✔
527
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
745,825✔
528

529
  SSingleWorkerCfg mgmtCfg = {.min = 1,
745,825✔
530
                              .max = 1,
531
                              .name = "vnode-mgmt",
532
                              .fp = (FItem)vmProcessMgmtQueue,
533
                              .param = pMgmt,
534
                              .threadCategory = THREAD_CAT_WRITE};
535

536
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
745,825✔
537

538
  int32_t threadNum = 0;
745,825✔
539
  if (tsNumOfCores == 1) {
745,825✔
540
    threadNum = 2;
×
541
  } else {
542
    threadNum = tsNumOfCores;
745,825✔
543
  }
544
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
745,825✔
545
                                   .max = threadNum,
546
                                   .name = "vnode-multi-mgmt",
547
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
548
                                   .param = pMgmt,
549
                                   .threadCategory = THREAD_CAT_WRITE};
550

551
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
745,825✔
552
  dDebug("vnode workers are initialized");
745,825✔
553
  return 0;
745,825✔
554
}
555

556
void vmStopWorker(SVnodeMgmt *pMgmt) {
745,825✔
557
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
745,825✔
558
  tWWorkerCleanup(&pMgmt->fetchPool);
745,825✔
559
  tQueryAutoQWorkerCleanup(&pMgmt->streamReaderPool);
745,825✔
560
  dDebug("vnode workers are closed");
745,825✔
561
}
745,825✔
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