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

taosdata / TDengine / #4884

14 Dec 2025 03:48AM UTC coverage: 60.617% (-4.1%) from 64.74%
#4884

push

travis-ci

web-flow
test: update coverage workflow time (#33918)

156854 of 258761 relevant lines covered (60.62%)

75258957.81 hits per line

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

81.37
/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,724,600✔
21
  if (pMsg->info.handle == NULL) return;
4,724,600✔
22
  SRpcMsg rsp = {
9,448,900✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
4,724,559✔
25
      .contLen = pMsg->info.rspLen,
4,723,766✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
4,723,810✔
29
}
30

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
1,547,317✔
37
  switch (pMsg->msgType) {
1,547,317✔
38
    case TDMT_DND_CREATE_VNODE:
1,544,973✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
1,544,973✔
40
      break;
1,543,079✔
41
#ifdef USE_MOUNT
42
    case TDMT_DND_RETRIEVE_MOUNT_PATH:
1,016✔
43
      code = vmProcessRetrieveMountPathReq(pMgmt, pMsg);
1,016✔
44
      break;
1,016✔
45
    case TDMT_DND_MOUNT_VNODE:
1,328✔
46
      code = vmProcessMountVnodeReq(pMgmt, pMsg);
1,328✔
47
      break;
1,328✔
48
#endif
49
  }
50

51
  if (IsReq(pMsg)) {
1,545,423✔
52
    if (code != 0) {
1,547,317✔
53
      if (terrno != 0) code = terrno;
684✔
54
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
684✔
55
    }
56
    vmSendRsp(pMsg, code);
1,547,317✔
57
  }
58

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
1,547,317✔
60
  rpcFreeCont(pMsg->pCont);
1,547,317✔
61
  taosFreeQitem(pMsg);
1,546,812✔
62
}
1,547,317✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
2,759,465✔
70
  switch (pMsg->msgType) {
2,759,465✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
967,129✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
967,129✔
76
      break;
967,129✔
77
    case TDMT_VND_ALTER_REPLICA:
410,322✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
410,322✔
79
      break;
410,322✔
80
    case TDMT_VND_DISABLE_WRITE:
13,563✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
13,563✔
82
      break;
13,563✔
83
    case TDMT_VND_SET_KEEP_VERSION:
2,079✔
84
      code = vmProcessSetKeepVersionReq(pMgmt, pMsg);
2,079✔
85
      break;
2,079✔
86
    case TDMT_VND_ALTER_HASHRANGE:
13,046✔
87
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
13,046✔
88
      break;
13,046✔
89
    case TDMT_DND_ALTER_VNODE_TYPE:
1,280,236✔
90
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
1,280,236✔
91
      break;
1,280,236✔
92
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
93
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
94
      break;
×
95
    case TDMT_VND_ARB_HEARTBEAT:
63,568✔
96
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
63,568✔
97
      break;
63,568✔
98
    case TDMT_VND_ALTER_ELECTBASELINE:
9,522✔
99
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
9,522✔
100
      break;
9,522✔
101
    default:
×
102
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
103
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
104
  }
105

106
  if (IsReq(pMsg)) {
2,759,465✔
107
    if (code != 0) {
2,759,465✔
108
      if (terrno != 0) code = terrno;
1,224,234✔
109
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
1,224,234✔
110
    }
111
    vmSendRsp(pMsg, code);
2,759,465✔
112
  }
113

114
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
2,759,465✔
115
  rpcFreeCont(pMsg->pCont);
2,759,465✔
116
  taosFreeQitem(pMsg);
2,759,465✔
117
}
2,759,465✔
118

119
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
77,935,270✔
120
  SVnodeObj      *pVnode = pInfo->ahandle;
77,935,270✔
121
  const STraceId *trace = &pMsg->info.traceId;
77,936,243✔
122

123
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
77,936,019✔
124
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
77,936,271✔
125
  if (code != 0) {
77,935,762✔
126
    if (terrno != 0) code = terrno;
×
127
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
×
128
    vmSendRsp(pMsg, code);
×
129
  }
130

131
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
77,935,762✔
132
  rpcFreeCont(pMsg->pCont);
77,935,762✔
133
  taosFreeQitem(pMsg);
77,935,901✔
134
}
77,934,588✔
135

136
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
213,731,793✔
137
  SVnodeObj *pVnode = pInfo->ahandle;
213,731,793✔
138
  SRpcMsg   *pMsg = NULL;
213,736,151✔
139

140
  for (int32_t i = 0; i < numOfMsgs; ++i) {
433,598,992✔
141
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
219,843,026✔
142
    const STraceId *trace = &pMsg->info.traceId;
219,858,892✔
143
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
219,868,249✔
144

145
    terrno = 0;
219,868,855✔
146
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
219,856,586✔
147
    if (code != 0) {
219,875,303✔
148
      if (code == -1 && terrno != 0) {
418,436✔
149
        code = terrno;
×
150
      }
151

152
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
418,436✔
153
        dGDebug("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
×
154
      } else {
155
        dGError("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
418,436✔
156
      }
157

158
      vmSendRsp(pMsg, code);
418,436✔
159
    }
160

161
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
219,875,303✔
162
    rpcFreeCont(pMsg->pCont);
219,875,303✔
163
    taosFreeQitem(pMsg);
219,875,292✔
164
  }
165
}
213,753,889✔
166

167
static void vmProcessStreamReaderQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
250,585✔
168
  SVnodeObj *pVnode = pInfo->ahandle;
250,585✔
169
  const STraceId *trace = &pMsg->info.traceId;
250,585✔
170
  dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
250,585✔
171

172
  terrno = 0;
250,585✔
173
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
250,585✔
174
  if (code != 0) {
250,585✔
175
    if (code == -1 && terrno != 0) {
4,147✔
176
      code = terrno;
×
177
    }
178

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

186
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
250,585✔
187
  rpcFreeCont(pMsg->pCont);
250,585✔
188
  taosFreeQitem(pMsg);
250,585✔
189
}
250,331✔
190

191
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
86,290,210✔
192
  SVnodeObj *pVnode = pInfo->ahandle;
86,290,210✔
193
  SRpcMsg   *pMsg = NULL;
86,290,210✔
194

195
  for (int32_t i = 0; i < numOfMsgs; ++i) {
176,768,783✔
196
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
90,484,568✔
197
    const STraceId *trace = &pMsg->info.traceId;
90,485,088✔
198
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
90,486,837✔
199

200
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
90,487,353✔
201
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
90,481,207✔
202
    rpcFreeCont(pMsg->pCont);
90,481,723✔
203
    taosFreeQitem(pMsg);
90,478,992✔
204
  }
205
}
86,286,202✔
206

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

216
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
304,220,211✔
217
  STfs *pTfs = pVnode->pImpl->pTfs;
304,220,211✔
218
  if (pTfs) {
304,223,267✔
219
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
304,223,267✔
220
  } else {
221
    return osDataSpaceSufficient();
×
222
  }
223
}
224

225
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
734,326,541✔
226
  *pNode = vmAcquireVnode(pMgt, vgId);
734,326,541✔
227
  if (*pNode == NULL) {
734,352,122✔
228
    return terrno;
1,010,175✔
229
  }
230
  return 0;
733,347,379✔
231
}
232
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
734,338,604✔
233
  int32_t         code = 0;
734,338,604✔
234
  SMsgHead *      pHead = pMsg->pCont;
734,338,604✔
235
  SVnodeObj *     pVnode = NULL;
734,317,975✔
236
  const STraceId *trace = &pMsg->info.traceId;
734,320,361✔
237

238
  if (pMsg->contLen < sizeof(SMsgHead)) {
734,325,118✔
239
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
240
            pMsg->contLen);
241
    return TSDB_CODE_INVALID_MSG;
×
242
  }
243

244
  pHead->contLen = ntohl(pHead->contLen);
734,336,148✔
245
  pHead->vgId = ntohl(pHead->vgId);
734,339,250✔
246
  
247
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
734,340,358✔
248
  if (code != 0) {
734,316,777✔
249
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
1,010,175✔
250
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
251
    return code;
1,010,175✔
252
  }
253

254
  switch (qtype) {
733,306,602✔
255
    case QUERY_QUEUE:
77,933,639✔
256
      // let's put into different query processing queue. The query type is extracted during preprocessing procedure,
257
      // mquery-queue for meta info query, and query-queue for ordinary users' queries.
258
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
77,933,639✔
259
      if (code) {
77,935,890✔
260
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
904✔
261
      } else {
262
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
77,934,986✔
263
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
77,934,986✔
264
      }
265
      break;
77,933,732✔
266
    case FETCH_QUEUE:
219,842,242✔
267
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
219,842,242✔
268
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
219,842,242✔
269
      break;
219,867,386✔
270
    case WRITE_QUEUE:
304,217,806✔
271
      if (!vmDataSpaceSufficient(pVnode)) {
304,217,806✔
272
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
273
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
274
               tstrerror(code), TMSG_INFO(pMsg->msgType));
275
        break;
×
276
      }
277
#if 0
278
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
279
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
280
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
281
               tstrerror(code), TMSG_INFO(pMsg->msgType));
282
        break;
283
      }
284
#endif
285
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
304,218,927✔
286
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
25,928✔
287
               TMSG_INFO(pMsg->msgType));
288
        code = TSDB_CODE_VND_STOPPED;
25,928✔
289
        break;
25,928✔
290
      }
291
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
304,190,997✔
292
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
304,190,997✔
293
      break;
304,196,372✔
294
    case SYNC_QUEUE:
72,351,914✔
295
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
72,351,914✔
296
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
72,351,914✔
297
      break;
72,352,054✔
298
    case SYNC_RD_QUEUE:
18,129,341✔
299
      if(tsSyncLogHeartbeat){
18,129,341✔
300
        dGInfo("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
×
301
      }
302
      else{
303
        dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
18,129,341✔
304
      }
305
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
18,129,341✔
306
      break;
18,132,762✔
307
    case APPLY_QUEUE:
40,581,329✔
308
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
40,581,329✔
309
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
40,581,329✔
310
      break;
40,582,175✔
311
    case STREAM_READER_QUEUE:
250,331✔
312
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
250,331✔
313
              TMSG_INFO(pMsg->msgType));
314
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
250,331✔
315
      break;
250,306✔
316
    default:
×
317
      code = TSDB_CODE_INVALID_MSG;
×
318
      break;
×
319
  }
320

321
  vmReleaseVnode(pMgmt, pVnode);
733,340,715✔
322
  return code;
733,339,101✔
323
}
324

325
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
18,248,632✔
326

327
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
45,208,297✔
328

329
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
303,785,796✔
330

331
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
73,964,629✔
332

333
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
219,907,489✔
334

335
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
252,109✔
336

337
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
1,546,783✔
338
  const STraceId *trace = &pMsg->info.traceId;
1,546,783✔
339
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
1,547,317✔
340
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
1,547,317✔
341
}
342

343
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
2,759,465✔
344
  const STraceId *trace = &pMsg->info.traceId;
2,759,465✔
345
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
2,759,465✔
346
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
2,759,465✔
347
}
348

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

359
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
72,985,313✔
360
  SRpcMsg *pMsg;
72,984,576✔
361
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
72,985,313✔
362
  if (code) {
72,985,315✔
363
    rpcFreeCont(pRpc->pCont);
×
364
    pRpc->pCont = NULL;
×
365
    return code;
×
366
  }
367

368
  SMsgHead *pHead = pRpc->pCont;
72,985,315✔
369
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
72,985,315✔
370

371
  pHead->contLen = htonl(pHead->contLen);
72,985,315✔
372
  pHead->vgId = htonl(pHead->vgId);
72,984,276✔
373
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
72,985,262✔
374
  pRpc->pCont = NULL;
72,985,262✔
375

376
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
72,984,772✔
377
  if (code != 0) {
72,985,805✔
378
    dTrace("msg:%p, is freed", pMsg);
742,522✔
379
    rpcFreeCont(pMsg->pCont);
742,522✔
380
    taosFreeQitem(pMsg);
742,522✔
381
  }
382

383
  return code;
72,985,600✔
384
}
385

386
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
9,082,785✔
387
  int32_t    size = -1;
9,082,785✔
388
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
9,082,785✔
389
  if (pVnode != NULL) {
9,082,110✔
390
    switch (qtype) {
4,734,432✔
391
      case WRITE_QUEUE:
×
392
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
393
        break;
×
394
      case SYNC_QUEUE:
×
395
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
396
        break;
×
397
      case APPLY_QUEUE:
4,734,432✔
398
        size = taosQueueItemSize(pVnode->pApplyW.queue);
4,734,432✔
399
        break;
4,735,615✔
400
      case QUERY_QUEUE:
×
401
        size = taosQueueItemSize(pVnode->pQueryQ);
×
402
        break;
×
403
      case FETCH_QUEUE:
×
404
        size = taosQueueItemSize(pVnode->pFetchQ);
×
405
        break;
×
406
      case STREAM_READER_QUEUE:
×
407
        size = taosQueueItemSize(pVnode->pStreamReaderQ);
×
408
        break;
×
409
      default:
×
410
        break;
×
411
    }
412
  }
413
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
9,083,293✔
414
  if (size < 0) {
9,082,197✔
415
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
4,347,165✔
416
    size = 0;
4,346,917✔
417
  }
418
  return size;
9,081,949✔
419
}
420

421
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
2,176,095✔
422
  int32_t         code = 0;
2,176,095✔
423
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
2,176,095✔
424
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
2,176,095✔
425
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
2,176,095✔
426
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
2,175,724✔
427
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
2,175,724✔
428
  if (code) {
2,176,095✔
429
    return code;
×
430
  }
431
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
2,176,095✔
432
  if (code) {
2,176,095✔
433
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
434
    return code;
×
435
  }
436
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
2,176,095✔
437
  if (code) {
2,176,095✔
438
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
439
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
440
    return code;
×
441
  }
442
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
2,176,095✔
443
  if (code) {
2,176,095✔
444
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
445
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
446
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
447
    return code;
×
448
  }
449

450
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
2,176,095✔
451
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
2,176,095✔
452
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
2,176,095✔
453

454
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
2,176,095✔
455
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
2,176,095✔
456
    return TSDB_CODE_OUT_OF_MEMORY;
×
457
  }
458

459
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
2,176,095✔
460
        taosQueueGetThreadId(pVnode->pWriteW.queue));
461
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
2,176,095✔
462
        taosQueueGetThreadId(pVnode->pSyncW.queue));
463
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
2,176,095✔
464
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
465
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
2,176,095✔
466
        taosQueueGetThreadId(pVnode->pApplyW.queue));
467
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
2,176,095✔
468
  dInfo("vgId:%d, stream-reader-queue:%p is alloced", pVnode->vgId, pVnode->pStreamReaderQ);
2,176,095✔
469
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
2,176,095✔
470
        taosQueueGetThreadId(pVnode->pFetchQ));
471
  return 0;
2,176,095✔
472
}
473

474
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
2,176,095✔
475
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
2,176,095✔
476
  tQueryAutoQWorkerFreeQueue(&pMgmt->streamReaderPool, pVnode->pStreamReaderQ);
2,176,095✔
477
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
2,176,095✔
478

479
  pVnode->pQueryQ = NULL;
2,176,095✔
480
  pVnode->pFetchQ = NULL;
2,176,095✔
481
  pVnode->pStreamReaderQ = NULL;
2,176,095✔
482
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
2,176,095✔
483
}
2,176,095✔
484

485
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
315,370✔
486
  int32_t code = 0;
315,370✔
487

488
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
315,370✔
489
  pQPool->name = "vnode-query";
315,370✔
490
  pQPool->min = tsNumOfVnodeQueryThreads;
315,370✔
491
  pQPool->max = tsNumOfVnodeQueryThreads;
315,370✔
492
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
315,370✔
493

494
  SQueryAutoQWorkerPool *pSPool = &pMgmt->streamReaderPool;
315,370✔
495
  pSPool->name = "vnode-st-reader";
315,370✔
496
  pSPool->min = tsNumOfVnodeStreamReaderThreads;
315,370✔
497
  pSPool->max = tsNumOfVnodeStreamReaderThreads;
315,370✔
498
  if ((code = tQueryAutoQWorkerInit(pSPool)) != 0) return code;
315,370✔
499

500
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
315,370✔
501

502
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
315,370✔
503
  pFPool->name = "vnode-fetch";
315,370✔
504
  pFPool->max = tsNumOfVnodeFetchThreads;
315,370✔
505
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
315,370✔
506

507
  SSingleWorkerCfg mgmtCfg = {
315,370✔
508
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
509

510
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
315,370✔
511

512
  int32_t threadNum = 0;
315,370✔
513
  if (tsNumOfCores == 1) {
315,370✔
514
    threadNum = 2;
×
515
  } else {
516
    threadNum = tsNumOfCores;
315,370✔
517
  }
518
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
315,370✔
519
                                   .max = threadNum,
520
                                   .name = "vnode-multi-mgmt",
521
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
522
                                   .param = pMgmt};
523

524
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
315,370✔
525
  dDebug("vnode workers are initialized");
315,370✔
526
  return 0;
315,370✔
527
}
528

529
void vmStopWorker(SVnodeMgmt *pMgmt) {
315,370✔
530
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
315,370✔
531
  tWWorkerCleanup(&pMgmt->fetchPool);
315,370✔
532
  tQueryAutoQWorkerCleanup(&pMgmt->streamReaderPool);
315,370✔
533
  dDebug("vnode workers are closed");
315,370✔
534
}
315,370✔
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