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

taosdata / TDengine / #4849

13 Nov 2025 07:17AM UTC coverage: 63.829% (+0.6%) from 63.27%
#4849

push

travis-ci

guanshengliang
test: enable auto upload

148928 of 233322 relevant lines covered (63.83%)

115593255.19 hits per line

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

81.22
/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) {
7,805,955✔
21
  if (pMsg->info.handle == NULL) return;
7,805,955✔
22
  SRpcMsg rsp = {
15,597,799✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
7,806,330✔
25
      .contLen = pMsg->info.rspLen,
7,805,580✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
7,806,330✔
29
}
30

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

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

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
2,934,112✔
60
  rpcFreeCont(pMsg->pCont);
2,934,112✔
61
  taosFreeQitem(pMsg);
2,934,037✔
62
}
2,933,742✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
4,140,838✔
70
  switch (pMsg->msgType) {
4,140,838✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
1,547,646✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
1,547,646✔
76
      break;
1,547,646✔
77
    case TDMT_VND_ALTER_REPLICA:
612,288✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
612,288✔
79
      break;
612,288✔
80
    case TDMT_VND_DISABLE_WRITE:
21,046✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
21,046✔
82
      break;
21,046✔
83
    case TDMT_VND_ALTER_HASHRANGE:
20,330✔
84
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
20,330✔
85
      break;
20,330✔
86
    case TDMT_DND_ALTER_VNODE_TYPE:
1,808,667✔
87
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
1,808,667✔
88
      break;
1,808,667✔
89
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
90
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
91
      break;
×
92
    case TDMT_VND_ARB_HEARTBEAT:
101,570✔
93
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
101,570✔
94
      break;
101,570✔
95
    case TDMT_VND_ALTER_ELECTBASELINE:
29,291✔
96
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
29,291✔
97
      break;
29,291✔
98
    default:
×
99
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
100
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
101
  }
102

103
  if (IsReq(pMsg)) {
4,140,838✔
104
    if (code != 0) {
4,140,838✔
105
      if (terrno != 0) code = terrno;
1,718,730✔
106
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
1,718,730✔
107
    }
108
    vmSendRsp(pMsg, code);
4,140,838✔
109
  }
110

111
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
4,140,838✔
112
  rpcFreeCont(pMsg->pCont);
4,140,838✔
113
  taosFreeQitem(pMsg);
4,140,838✔
114
}
4,140,838✔
115

116
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
213,370,099✔
117
  SVnodeObj      *pVnode = pInfo->ahandle;
213,370,099✔
118
  const STraceId *trace = &pMsg->info.traceId;
213,374,532✔
119

120
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
213,373,918✔
121
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
213,373,918✔
122
  if (code != 0) {
213,371,157✔
123
    if (terrno != 0) code = terrno;
72,692✔
124
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
72,692✔
125
    vmSendRsp(pMsg, code);
72,692✔
126
  }
127

128
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
213,371,157✔
129
  rpcFreeCont(pMsg->pCont);
213,371,157✔
130
  taosFreeQitem(pMsg);
213,371,277✔
131
}
213,371,415✔
132

133
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
486,214,833✔
134
  SVnodeObj *pVnode = pInfo->ahandle;
486,214,833✔
135
  SRpcMsg   *pMsg = NULL;
486,224,574✔
136

137
  for (int32_t i = 0; i < numOfMsgs; ++i) {
986,419,073✔
138
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
500,132,777✔
139
    const STraceId *trace = &pMsg->info.traceId;
500,158,457✔
140
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
500,184,185✔
141

142
    terrno = 0;
500,184,185✔
143
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
500,175,955✔
144
    if (code != 0) {
500,212,822✔
145
      if (code == -1 && terrno != 0) {
658,074✔
146
        code = terrno;
×
147
      }
148

149
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
658,074✔
150
        dGDebug("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
×
151
      } else {
152
        dGError("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
658,074✔
153
      }
154

155
      vmSendRsp(pMsg, code);
658,074✔
156
    }
157

158
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
500,212,822✔
159
    rpcFreeCont(pMsg->pCont);
500,212,822✔
160
    taosFreeQitem(pMsg);
500,203,705✔
161
  }
162
}
486,286,945✔
163

164
static void vmProcessStreamReaderQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
27,458,917✔
165
  SVnodeObj *pVnode = pInfo->ahandle;
27,458,917✔
166
  const STraceId *trace = &pMsg->info.traceId;
27,458,912✔
167
  dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
27,456,645✔
168

169
  terrno = 0;
27,456,645✔
170
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
27,460,076✔
171
  if (code != 0) {
27,447,250✔
172
    if (code == -1 && terrno != 0) {
×
173
      code = terrno;
×
174
    }
175

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

183
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
27,447,250✔
184
  rpcFreeCont(pMsg->pCont);
27,447,250✔
185
  taosFreeQitem(pMsg);
27,448,102✔
186
}
27,446,816✔
187

188
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
189,966,788✔
189
  SVnodeObj *pVnode = pInfo->ahandle;
189,966,788✔
190
  SRpcMsg   *pMsg = NULL;
189,968,392✔
191

192
  for (int32_t i = 0; i < numOfMsgs; ++i) {
390,546,683✔
193
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
200,588,767✔
194
    const STraceId *trace = &pMsg->info.traceId;
200,584,235✔
195
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
200,589,984✔
196

197
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
200,589,984✔
198
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
200,583,501✔
199
    rpcFreeCont(pMsg->pCont);
200,584,378✔
200
    taosFreeQitem(pMsg);
200,563,442✔
201
  }
202
}
189,957,916✔
203

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

213
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
541,294,017✔
214
  STfs *pTfs = pVnode->pImpl->pTfs;
541,294,017✔
215
  if (pTfs) {
541,304,234✔
216
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
541,304,234✔
217
  } else {
218
    return osDataSpaceSufficient();
×
219
  }
220
}
221

222
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
1,564,486,948✔
223
  *pNode = vmAcquireVnode(pMgt, vgId);
1,564,486,948✔
224
  if (*pNode == NULL) {
1,564,606,309✔
225
    return terrno;
1,897,733✔
226
  }
227
  return 0;
1,562,597,888✔
228
}
229
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
1,564,513,675✔
230
  int32_t         code = 0;
1,564,513,675✔
231
  SMsgHead *      pHead = pMsg->pCont;
1,564,513,675✔
232
  SVnodeObj *     pVnode = NULL;
1,564,470,403✔
233
  const STraceId *trace = &pMsg->info.traceId;
1,564,471,165✔
234

235
  if (pMsg->contLen < sizeof(SMsgHead)) {
1,564,493,549✔
236
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
237
            pMsg->contLen);
238
    return TSDB_CODE_INVALID_MSG;
×
239
  }
240

241
  pHead->contLen = ntohl(pHead->contLen);
1,564,472,888✔
242
  pHead->vgId = ntohl(pHead->vgId);
1,564,507,099✔
243
  
244
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
1,564,557,374✔
245
  if (code != 0) {
1,564,476,823✔
246
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
1,897,733✔
247
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
248
    return code;
1,897,733✔
249
  }
250

251
  switch (qtype) {
1,562,579,090✔
252
    case QUERY_QUEUE:
213,364,711✔
253
      // let's put into different query processing queue. The query type is extracted during preprocessing procedure,
254
      // mquery-queue for meta info query, and query-queue for ordinary users' queries.
255
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
213,364,711✔
256
      if (code) {
213,369,469✔
257
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
1,317✔
258
      } else {
259
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
213,368,152✔
260
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
213,369,610✔
261
      }
262
      break;
213,368,912✔
263
    case FETCH_QUEUE:
500,151,571✔
264
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
500,151,571✔
265
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
500,151,571✔
266
      break;
500,200,325✔
267
    case WRITE_QUEUE:
541,293,036✔
268
      if (!vmDataSpaceSufficient(pVnode)) {
541,293,036✔
269
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
270
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
271
               tstrerror(code), TMSG_INFO(pMsg->msgType));
272
        break;
×
273
      }
274
#if 0
275
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
276
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
277
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
278
               tstrerror(code), TMSG_INFO(pMsg->msgType));
279
        break;
280
      }
281
#endif
282
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
541,290,910✔
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
52,240✔
284
               TMSG_INFO(pMsg->msgType));
285
        code = TSDB_CODE_VND_STOPPED;
52,240✔
286
        break;
52,240✔
287
      }
288
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
541,230,060✔
289
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
541,230,838✔
290
      break;
541,249,113✔
291
    case SYNC_QUEUE:
154,816,680✔
292
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
154,816,680✔
293
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
154,816,680✔
294
      break;
154,819,868✔
295
    case SYNC_RD_QUEUE:
45,760,633✔
296
      if(tsSyncLogHeartbeat){
45,760,633✔
297
        dGInfo("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
×
298
      }
299
      else{
300
        dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
45,760,633✔
301
      }
302
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
45,760,633✔
303
      break;
45,768,427✔
304
    case APPLY_QUEUE:
79,762,037✔
305
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
79,762,037✔
306
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
79,762,037✔
307
      break;
79,762,811✔
308
    case STREAM_READER_QUEUE:
27,430,422✔
309
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
27,430,422✔
310
              TMSG_INFO(pMsg->msgType));
311
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
27,430,722✔
312
      break;
27,453,772✔
313
    default:
×
314
      code = TSDB_CODE_INVALID_MSG;
×
315
      break;
×
316
  }
317

318
  vmReleaseVnode(pMgmt, pVnode);
1,562,675,468✔
319
  return code;
1,562,672,934✔
320
}
321

322
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
46,014,208✔
323

324
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
91,403,704✔
325

326
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
540,403,651✔
327

328
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
165,561,274✔
329

330
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
500,269,939✔
331

332
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
27,449,597✔
333

334
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
2,931,687✔
335
  const STraceId *trace = &pMsg->info.traceId;
2,931,687✔
336
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
2,934,670✔
337
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
2,934,670✔
338
}
339

340
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
4,140,233✔
341
  const STraceId *trace = &pMsg->info.traceId;
4,140,233✔
342
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
4,140,838✔
343
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
4,140,838✔
344
}
345

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

356
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
193,455,217✔
357
  SRpcMsg *pMsg;
193,430,095✔
358
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
193,456,178✔
359
  if (code) {
193,454,893✔
360
    rpcFreeCont(pRpc->pCont);
×
361
    pRpc->pCont = NULL;
×
362
    return code;
×
363
  }
364

365
  SMsgHead *pHead = pRpc->pCont;
193,454,893✔
366
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
193,455,365✔
367

368
  pHead->contLen = htonl(pHead->contLen);
193,455,365✔
369
  pHead->vgId = htonl(pHead->vgId);
193,454,914✔
370
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
193,455,751✔
371
  pRpc->pCont = NULL;
193,455,751✔
372

373
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
193,457,134✔
374
  if (code != 0) {
193,455,930✔
375
    dTrace("msg:%p, is freed", pMsg);
1,329,730✔
376
    rpcFreeCont(pMsg->pCont);
1,329,730✔
377
    taosFreeQitem(pMsg);
1,329,730✔
378
  }
379

380
  return code;
193,454,270✔
381
}
382

383
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
16,256,527✔
384
  int32_t    size = -1;
16,256,527✔
385
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
16,256,527✔
386
  if (pVnode != NULL) {
16,257,039✔
387
    switch (qtype) {
8,224,392✔
388
      case WRITE_QUEUE:
×
389
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
390
        break;
×
391
      case SYNC_QUEUE:
×
392
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
393
        break;
×
394
      case APPLY_QUEUE:
8,224,392✔
395
        size = taosQueueItemSize(pVnode->pApplyW.queue);
8,224,392✔
396
        break;
8,225,283✔
397
      case QUERY_QUEUE:
×
398
        size = taosQueueItemSize(pVnode->pQueryQ);
×
399
        break;
×
400
      case FETCH_QUEUE:
×
401
        size = taosQueueItemSize(pVnode->pFetchQ);
×
402
        break;
×
403
      case STREAM_READER_QUEUE:
×
404
        size = taosQueueItemSize(pVnode->pStreamReaderQ);
×
405
        break;
×
406
      default:
×
407
        break;
×
408
    }
409
  }
410
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
16,257,930✔
411
  if (size < 0) {
16,255,506✔
412
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
8,030,212✔
413
    size = 0;
8,030,212✔
414
  }
415
  return size;
16,255,506✔
416
}
417

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

447
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
4,022,655✔
448
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
4,022,655✔
449
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
4,022,655✔
450

451
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
4,022,655✔
452
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
4,022,655✔
453
    return TSDB_CODE_OUT_OF_MEMORY;
×
454
  }
455

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

471
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
4,022,651✔
472
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
4,022,651✔
473
  tQueryAutoQWorkerFreeQueue(&pMgmt->streamReaderPool, pVnode->pStreamReaderQ);
4,022,655✔
474
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
4,022,655✔
475

476
  pVnode->pQueryQ = NULL;
4,022,655✔
477
  pVnode->pFetchQ = NULL;
4,022,655✔
478
  pVnode->pStreamReaderQ = NULL;
4,022,655✔
479
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
4,022,655✔
480
}
4,022,655✔
481

482
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
655,334✔
483
  int32_t code = 0;
655,334✔
484

485
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
655,334✔
486
  pQPool->name = "vnode-query";
655,334✔
487
  pQPool->min = tsNumOfVnodeQueryThreads;
655,334✔
488
  pQPool->max = tsNumOfVnodeQueryThreads;
655,334✔
489
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
655,334✔
490

491
  SQueryAutoQWorkerPool *pSPool = &pMgmt->streamReaderPool;
655,334✔
492
  pSPool->name = "vnode-st-reader";
655,334✔
493
  pSPool->min = tsNumOfVnodeStreamReaderThreads;
655,334✔
494
  pSPool->max = tsNumOfVnodeStreamReaderThreads;
655,334✔
495
  if ((code = tQueryAutoQWorkerInit(pSPool)) != 0) return code;
655,334✔
496

497
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
655,334✔
498

499
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
655,334✔
500
  pFPool->name = "vnode-fetch";
655,334✔
501
  pFPool->max = tsNumOfVnodeFetchThreads;
655,334✔
502
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
655,334✔
503

504
  SSingleWorkerCfg mgmtCfg = {
655,334✔
505
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
506

507
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
655,334✔
508

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

521
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
655,334✔
522
  dDebug("vnode workers are initialized");
655,334✔
523
  return 0;
655,334✔
524
}
525

526
void vmStopWorker(SVnodeMgmt *pMgmt) {
655,334✔
527
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
655,334✔
528
  tWWorkerCleanup(&pMgmt->fetchPool);
655,334✔
529
  tQueryAutoQWorkerCleanup(&pMgmt->streamReaderPool);
655,334✔
530
  dDebug("vnode workers are closed");
655,334✔
531
}
655,334✔
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