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

taosdata / TDengine / #4912

04 Jan 2026 09:05AM UTC coverage: 64.888% (-0.1%) from 65.028%
#4912

push

travis-ci

web-flow
merge: from main to 3.0 branch #34156

1206 of 4524 new or added lines in 22 files covered. (26.66%)

5351 existing lines in 123 files now uncovered.

194856 of 300296 relevant lines covered (64.89%)

118198896.2 hits per line

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

81.92
/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,697,208✔
21
  if (pMsg->info.handle == NULL) return;
7,697,208✔
22
  SRpcMsg rsp = {
15,393,246✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
7,696,729✔
25
      .contLen = pMsg->info.rspLen,
7,697,032✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
7,697,032✔
29
}
30

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

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

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
2,606,875✔
60
  rpcFreeCont(pMsg->pCont);
2,606,875✔
61
  taosFreeQitem(pMsg);
2,607,615✔
62
}
2,608,344✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
4,162,453✔
70
  switch (pMsg->msgType) {
4,162,453✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
1,393,596✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
1,393,596✔
76
      break;
1,393,596✔
77
    case TDMT_VND_ALTER_REPLICA:
654,987✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
654,987✔
79
      break;
654,987✔
80
    case TDMT_VND_DISABLE_WRITE:
30,965✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
30,965✔
82
      break;
30,965✔
83
    case TDMT_VND_SET_KEEP_VERSION:
3,117✔
84
      code = vmProcessSetKeepVersionReq(pMgmt, pMsg);
3,117✔
85
      break;
3,117✔
86
    case TDMT_VND_ALTER_HASHRANGE:
30,297✔
87
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
30,297✔
88
      break;
30,297✔
89
    case TDMT_DND_ALTER_VNODE_TYPE:
1,931,016✔
90
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
1,931,016✔
91
      break;
1,931,016✔
92
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
93
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
94
      break;
×
95
    case TDMT_VND_ARB_HEARTBEAT:
96,601✔
96
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
96,601✔
97
      break;
96,601✔
98
    case TDMT_VND_ALTER_ELECTBASELINE:
21,874✔
99
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
21,874✔
100
      break;
21,874✔
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)) {
4,162,453✔
107
    if (code != 0) {
4,162,453✔
108
      if (terrno != 0) code = terrno;
1,836,412✔
109
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
1,836,412✔
110
    }
111
    vmSendRsp(pMsg, code);
4,162,453✔
112
  }
113

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

119
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
391,294,668✔
120
  SVnodeObj      *pVnode = pInfo->ahandle;
391,294,668✔
121
  const STraceId *trace = &pMsg->info.traceId;
391,299,477✔
122

123
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
391,297,109✔
124
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
391,297,109✔
125
  if (code != 0) {
391,231,056✔
126
    if (terrno != 0) code = terrno;
260,384✔
127
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
260,384✔
128
    vmSendRsp(pMsg, code);
260,384✔
129
  }
130

131
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
391,231,056✔
132
  rpcFreeCont(pMsg->pCont);
391,231,056✔
133
  taosFreeQitem(pMsg);
391,250,033✔
134
}
391,244,934✔
135

136
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
828,156,244✔
137
  SVnodeObj *pVnode = pInfo->ahandle;
828,156,244✔
138
  SRpcMsg   *pMsg = NULL;
828,165,142✔
139

140
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,703,030,826✔
141
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
874,780,328✔
142
    const STraceId *trace = &pMsg->info.traceId;
874,887,112✔
143
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
874,899,599✔
144

145
    terrno = 0;
874,899,599✔
146
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
874,862,561✔
147
    if (code != 0) {
874,891,989✔
148
      if (code == -1 && terrno != 0) {
666,027✔
149
        code = terrno;
×
150
      }
151

152
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
666,027✔
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());
666,027✔
156
      }
157

158
      vmSendRsp(pMsg, code);
666,027✔
159
    }
160

161
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
874,891,989✔
162
    rpcFreeCont(pMsg->pCont);
874,891,989✔
163
    taosFreeQitem(pMsg);
874,875,389✔
164
  }
165
}
828,216,046✔
166

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

172
  terrno = 0;
27,884,078✔
173
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
27,885,065✔
174
  if (code != 0) {
27,880,136✔
175
    if (code == -1 && terrno != 0) {
65,059✔
176
      code = terrno;
×
177
    }
178

179
    if (code == 0) {
65,059✔
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());
65,059✔
183
    }
184
  }
185

186
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
27,880,136✔
187
  rpcFreeCont(pMsg->pCont);
27,880,136✔
188
  taosFreeQitem(pMsg);
27,878,584✔
189
}
27,881,360✔
190

191
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
281,523,219✔
192
  SVnodeObj *pVnode = pInfo->ahandle;
281,523,219✔
193
  SRpcMsg   *pMsg = NULL;
281,524,492✔
194

195
  for (int32_t i = 0; i < numOfMsgs; ++i) {
588,716,009✔
196
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
307,190,242✔
197
    const STraceId *trace = &pMsg->info.traceId;
307,183,114✔
198
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
307,178,733✔
199

200
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
307,178,733✔
201
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
307,186,777✔
202
    rpcFreeCont(pMsg->pCont);
307,187,331✔
203
    taosFreeQitem(pMsg);
307,174,267✔
204
  }
205
}
281,529,767✔
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) {
594,535,820✔
217
  STfs *pTfs = pVnode->pImpl->pTfs;
594,535,820✔
218
  if (pTfs) {
594,538,769✔
219
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
594,538,769✔
220
  } else {
221
    return osDataSpaceSufficient();
×
222
  }
223
}
224

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

238
  if (pMsg->contLen < sizeof(SMsgHead)) {
2,147,483,647✔
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);
2,147,483,647✔
245
  pHead->vgId = ntohl(pHead->vgId);
2,147,483,647✔
246
  
247
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
2,147,483,647✔
248
  if (code != 0) {
2,147,483,647✔
249
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
2,825,913✔
250
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
251
    return code;
2,825,913✔
252
  }
253

254
  switch (qtype) {
2,147,483,647✔
255
    case QUERY_QUEUE:
391,205,787✔
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);
391,205,787✔
259
      if (code) {
391,170,132✔
260
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
261
      } else {
262
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
391,170,132✔
263
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
391,170,132✔
264
      }
265
      break;
391,192,809✔
266
    case FETCH_QUEUE:
874,713,300✔
267
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
874,713,300✔
268
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
874,713,300✔
269
      break;
874,909,498✔
270
    case WRITE_QUEUE:
594,532,165✔
271
      if (!vmDataSpaceSufficient(pVnode)) {
594,532,165✔
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) {
594,528,876✔
286
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
190,405✔
287
               TMSG_INFO(pMsg->msgType));
288
        code = TSDB_CODE_VND_STOPPED;
190,405✔
289
        break;
190,405✔
290
      }
291
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
594,337,521✔
292
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
594,337,521✔
293
      break;
594,349,467✔
294
    case SYNC_QUEUE:
260,057,105✔
295
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
260,057,105✔
296
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
260,057,105✔
297
      break;
260,068,940✔
298
    case SYNC_RD_QUEUE:
47,118,654✔
299
      if(tsSyncLogHeartbeat){
47,118,654✔
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));
47,118,654✔
304
      }
305
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
47,118,654✔
306
      break;
47,123,169✔
307
    case APPLY_QUEUE:
170,674,838✔
308
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
170,674,838✔
309
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
170,674,838✔
310
      break;
170,674,812✔
311
    case STREAM_READER_QUEUE:
27,872,281✔
312
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
27,872,281✔
313
              TMSG_INFO(pMsg->msgType));
314
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
27,872,281✔
315
      break;
27,884,037✔
UNCOV
316
    default:
×
UNCOV
317
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
318
      break;
×
319
  }
320

321
  vmReleaseVnode(pMgmt, pVnode);
2,147,483,647✔
322
  return code;
2,147,483,647✔
323
}
324

325
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
47,302,433✔
326

327
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
177,523,712✔
328

329
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
593,740,687✔
330

331
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
371,697,126✔
332

333
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
874,817,578✔
334

335
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
27,890,886✔
336

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

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

349
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
276,059,573✔
350
  int32_t code;
351
  if (pRpc->contLen < sizeof(SMsgHead)) {
276,059,573✔
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;
276,060,282✔
360
  SRpcMsg *pMsg;
276,058,114✔
361
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
276,060,897✔
362
  if (code) {
276,060,882✔
363
    rpcFreeCont(pRpc->pCont);
×
364
    pRpc->pCont = NULL;
×
365
    return code;
×
366
  }
367

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

371
  pHead->contLen = htonl(pHead->contLen);
276,060,882✔
372
  pHead->vgId = htonl(pHead->vgId);
276,061,180✔
373
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
276,060,834✔
374
  pRpc->pCont = NULL;
276,060,834✔
375

376
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
276,061,260✔
377
  if (code != 0) {
276,059,601✔
378
    dTrace("msg:%p, is freed", pMsg);
1,359,733✔
379
    rpcFreeCont(pMsg->pCont);
1,359,733✔
380
    taosFreeQitem(pMsg);
1,359,733✔
381
  }
382

383
  return code;
276,061,183✔
384
}
385

386
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
15,820,969✔
387
  int32_t    size = -1;
15,820,969✔
388
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
15,820,969✔
389
  if (pVnode != NULL) {
15,822,882✔
390
    switch (qtype) {
8,507,113✔
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:
8,507,113✔
398
        size = taosQueueItemSize(pVnode->pApplyW.queue);
8,507,113✔
399
        break;
8,508,660✔
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);
15,824,429✔
414
  if (size < 0) {
15,822,779✔
415
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
7,313,568✔
416
    size = 0;
7,312,299✔
417
  }
418
  return size;
15,821,510✔
419
}
420

421
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
3,661,680✔
422
  int32_t         code = 0;
3,661,680✔
423
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
3,661,680✔
424
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
3,661,680✔
425
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
3,661,680✔
426
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
3,661,680✔
427
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
3,661,680✔
428
  if (code) {
3,661,680✔
429
    return code;
×
430
  }
431
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
3,661,680✔
432
  if (code) {
3,661,680✔
433
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
434
    return code;
×
435
  }
436
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
3,661,680✔
437
  if (code) {
3,661,680✔
438
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
439
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
440
    return code;
×
441
  }
442
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
3,661,680✔
443
  if (code) {
3,661,680✔
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);
3,661,680✔
451
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
3,661,680✔
452
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
3,661,680✔
453

454
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
3,661,680✔
455
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
3,661,680✔
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,
3,661,680✔
460
        taosQueueGetThreadId(pVnode->pWriteW.queue));
461
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
3,661,680✔
462
        taosQueueGetThreadId(pVnode->pSyncW.queue));
463
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
3,661,680✔
464
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
465
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
3,661,680✔
466
        taosQueueGetThreadId(pVnode->pApplyW.queue));
467
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
3,661,680✔
468
  dInfo("vgId:%d, stream-reader-queue:%p is alloced", pVnode->vgId, pVnode->pStreamReaderQ);
3,661,680✔
469
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
3,661,680✔
470
        taosQueueGetThreadId(pVnode->pFetchQ));
471
  return 0;
3,661,680✔
472
}
473

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

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

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

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

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

500
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
532,326✔
501

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

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

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

512
  int32_t threadNum = 0;
532,326✔
513
  if (tsNumOfCores == 1) {
532,326✔
514
    threadNum = 2;
×
515
  } else {
516
    threadNum = tsNumOfCores;
532,326✔
517
  }
518
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
532,326✔
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;
532,326✔
525
  dDebug("vnode workers are initialized");
532,326✔
526
  return 0;
532,326✔
527
}
528

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