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

taosdata / TDengine / #4768

01 Oct 2025 04:06AM UTC coverage: 57.85% (-0.8%) from 58.606%
#4768

push

travis-ci

web-flow
Merge pull request #33171 from taosdata/merge/3.3.6tomain

merge: from 3.3.6 to main branch

137167 of 302743 branches covered (45.31%)

Branch coverage included in aggregate %.

15 of 20 new or added lines in 2 files covered. (75.0%)

12125 existing lines in 175 files now uncovered.

208282 of 294403 relevant lines covered (70.75%)

5618137.93 hits per line

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

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

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
9,788!
37
  switch (pMsg->msgType) {
9,788!
38
    case TDMT_DND_CREATE_VNODE:
9,932✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
9,932✔
40
      break;
9,935✔
41
#ifdef USE_MOUNT
42
    case TDMT_DND_RETRIEVE_MOUNT_PATH:
6✔
43
      code = vmProcessRetrieveMountPathReq(pMgmt, pMsg);
6✔
44
      break;
6✔
45
    case TDMT_DND_MOUNT_VNODE:
8✔
46
      code = vmProcessMountVnodeReq(pMgmt, pMsg);
8✔
47
      break;
8✔
48
#endif
49
  }
50

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
9,789!
60
  rpcFreeCont(pMsg->pCont);
9,789✔
61
  taosFreeQitem(pMsg);
9,949✔
62
}
9,949✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
9,398!
70
  switch (pMsg->msgType) {
9,398!
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
4,192✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
4,192✔
76
      break;
4,192✔
77
    case TDMT_VND_ALTER_REPLICA:
1,197✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
1,197✔
79
      break;
1,197✔
80
    case TDMT_VND_DISABLE_WRITE:
64✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
64✔
82
      break;
64✔
83
    case TDMT_VND_ALTER_HASHRANGE:
63✔
84
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
63✔
85
      break;
63✔
86
    case TDMT_DND_ALTER_VNODE_TYPE:
3,552✔
87
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
3,552✔
88
      break;
3,552✔
89
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
90
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
91
      break;
×
92
    case TDMT_VND_ARB_HEARTBEAT:
240✔
93
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
240✔
94
      break;
240✔
95
    case TDMT_VND_ALTER_ELECTBASELINE:
90✔
96
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
90✔
97
      break;
90✔
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)) {
9,398!
104
    if (code != 0) {
9,398✔
105
      if (terrno != 0) code = terrno;
3,373!
106
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
3,373!
107
    }
108
    vmSendRsp(pMsg, code);
9,398✔
109
  }
110

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

116
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
1,533,285✔
117
  SVnodeObj      *pVnode = pInfo->ahandle;
1,533,285✔
118
  const STraceId *trace = &pMsg->info.traceId;
1,533,285✔
119

120
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
1,533,285!
121
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
1,533,285✔
122
  if (code != 0) {
1,533,242✔
123
    if (terrno != 0) code = terrno;
1,255!
124
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
1,254!
125
    vmSendRsp(pMsg, code);
1,255✔
126
  }
127

128
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,533,242!
129
  rpcFreeCont(pMsg->pCont);
1,533,242✔
130
  taosFreeQitem(pMsg);
1,533,284✔
131
}
1,533,289✔
132

133
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
3,807,763✔
134
  SVnodeObj *pVnode = pInfo->ahandle;
3,807,763✔
135
  SRpcMsg   *pMsg = NULL;
3,807,763✔
136

137
  for (int32_t i = 0; i < numOfMsgs; ++i) {
7,648,705✔
138
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
3,839,850!
139
    const STraceId *trace = &pMsg->info.traceId;
3,840,617✔
140
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
3,840,617!
141

142
    terrno = 0;
3,840,618✔
143
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
3,839,775✔
144
    if (code != 0) {
3,840,829✔
145
      if (code == -1 && terrno != 0) {
1,788!
146
        code = terrno;
×
147
      }
148

149
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
1,788!
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());
1,788!
153
      }
154

155
      vmSendRsp(pMsg, code);
1,788✔
156
    }
157

158
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
3,840,829!
159
    rpcFreeCont(pMsg->pCont);
3,840,829✔
160
    taosFreeQitem(pMsg);
3,840,947✔
161
  }
162
}
3,808,855✔
163

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

169
  terrno = 0;
81,596✔
170
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
81,591✔
171
  if (code != 0) {
81,523✔
172
    if (code == -1 && terrno != 0) {
391!
173
      code = terrno;
×
174
    }
175

176
    if (code == 0) {
391!
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());
391!
180
    }
181
  }
182

183
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
81,523!
184
  rpcFreeCont(pMsg->pCont);
81,523✔
185
  taosFreeQitem(pMsg);
81,559✔
186
}
81,575✔
187

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

192
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,429,650✔
193
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
752,986!
194
    const STraceId *trace = &pMsg->info.traceId;
753,228✔
195
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
753,228!
196

197
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
753,228✔
198
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
753,291!
199
    rpcFreeCont(pMsg->pCont);
753,291✔
200
    taosFreeQitem(pMsg);
753,267✔
201
  }
202
}
676,664✔
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) {
1,854,497✔
214
  STfs *pTfs = pVnode->pImpl->pTfs;
1,854,497✔
215
  if (pTfs) {
1,854,497!
216
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
1,854,539✔
217
  } else {
218
    return osDataSpaceSufficient();
×
219
  }
220
}
221

222
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
8,500,302✔
223
  *pNode = vmAcquireVnode(pMgt, vgId);
8,500,302✔
224
  if (*pNode == NULL) {
8,501,059✔
225
    return terrno;
8,481✔
226
  }
227
  return 0;
8,492,578✔
228
}
229
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
8,500,022✔
230
  int32_t         code = 0;
8,500,022✔
231
  SMsgHead *      pHead = pMsg->pCont;
8,500,022✔
232
  SVnodeObj *     pVnode = NULL;
8,500,022✔
233
  const STraceId *trace = &pMsg->info.traceId;
8,500,022✔
234

235
  if (pMsg->contLen < sizeof(SMsgHead)) {
8,500,022!
UNCOV
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);
UNCOV
238
    return TSDB_CODE_INVALID_MSG;
×
239
  }
240

241
  pHead->contLen = ntohl(pHead->contLen);
8,500,022✔
242
  pHead->vgId = ntohl(pHead->vgId);
8,500,022✔
243
  
244
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
8,500,022✔
245
  if (code != 0) {
8,501,021✔
246
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
8,487!
247
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
248
    return code;
8,487✔
249
  }
250

251
  switch (qtype) {
8,492,534✔
252
    case QUERY_QUEUE:
1,533,075✔
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);
1,533,075✔
256
      if (code) {
1,533,075✔
257
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
3!
258
      } else {
259
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,533,072!
260
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
1,533,072✔
261
      }
262
      break;
1,533,118✔
263
    case FETCH_QUEUE:
3,840,557✔
264
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
3,840,557!
265
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
3,840,558✔
266
      break;
3,840,800✔
267
    case WRITE_QUEUE:
1,854,506✔
268
      if (!vmDataSpaceSufficient(pVnode)) {
1,854,506!
UNCOV
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));
UNCOV
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) {
1,854,500✔
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
438!
284
               TMSG_INFO(pMsg->msgType));
285
        code = TSDB_CODE_VND_STOPPED;
438✔
286
        break;
438✔
287
      }
288
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,854,062!
289
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
1,854,063✔
290
      break;
1,854,090✔
291
    case SYNC_QUEUE:
631,442✔
292
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
631,442!
293
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
631,442✔
294
      break;
631,444✔
295
    case SYNC_RD_QUEUE:
121,842✔
296
      if(tsSyncLogHeartbeat){
121,842!
UNCOV
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));
121,842!
301
      }
302
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
121,842✔
303
      break;
121,860✔
304
    case APPLY_QUEUE:
428,992✔
305
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
428,992!
306
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
428,992✔
307
      break;
428,991✔
308
    case STREAM_READER_QUEUE:
81,496✔
309
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
81,496!
310
              TMSG_INFO(pMsg->msgType));
311
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
81,496✔
312
      break;
81,550✔
313
    default:
624✔
314
      code = TSDB_CODE_INVALID_MSG;
624✔
315
      break;
624✔
316
  }
317

318
  vmReleaseVnode(pMgmt, pVnode);
8,492,915✔
319
  return code;
8,492,449✔
320
}
321

322
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
122,268✔
323

324
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
425,227✔
325

326
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
1,850,823✔
327

328
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
1,440,429✔
329

330
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
3,840,795✔
331

332
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
81,488✔
333

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

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

346
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
739,205✔
347
  int32_t code;
348
  if (pRpc->contLen < sizeof(SMsgHead)) {
739,205!
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);
×
UNCOV
352
    pRpc->pCont = NULL;
×
UNCOV
353
    return TSDB_CODE_INVALID_MSG;
×
354
  }
355

356
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
739,205✔
357
  SRpcMsg *pMsg;
358
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
739,205✔
359
  if (code) {
739,203!
360
    rpcFreeCont(pRpc->pCont);
×
UNCOV
361
    pRpc->pCont = NULL;
×
UNCOV
362
    return code;
×
363
  }
364

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

368
  pHead->contLen = htonl(pHead->contLen);
739,203✔
369
  pHead->vgId = htonl(pHead->vgId);
739,203✔
370
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
739,203✔
371
  pRpc->pCont = NULL;
739,203✔
372

373
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
739,203✔
374
  if (code != 0) {
739,197✔
375
    dTrace("msg:%p, is freed", pMsg);
4,362✔
376
    rpcFreeCont(pMsg->pCont);
4,362✔
377
    taosFreeQitem(pMsg);
4,361✔
378
  }
379

380
  return code;
739,198✔
381
}
382

383
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
48,326✔
384
  int32_t    size = -1;
48,326✔
385
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
48,326✔
386
  if (pVnode != NULL) {
48,335✔
387
    switch (qtype) {
23,390!
388
      case WRITE_QUEUE:
×
389
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
390
        break;
×
391
      case SYNC_QUEUE:
×
UNCOV
392
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
UNCOV
393
        break;
×
394
      case APPLY_QUEUE:
23,390✔
395
        size = taosQueueItemSize(pVnode->pApplyW.queue);
23,390✔
396
        break;
23,391✔
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;
×
UNCOV
406
      default:
×
UNCOV
407
        break;
×
408
    }
409
  }
410
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
48,336✔
411
  if (size < 0) {
48,325✔
412
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
24,933✔
413
    size = 0;
24,940✔
414
  }
415
  return size;
48,332✔
416
}
417

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

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

451
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
12,523!
452
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
12,523!
UNCOV
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,
12,523!
457
        taosQueueGetThreadId(pVnode->pWriteW.queue));
458
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
12,523!
459
        taosQueueGetThreadId(pVnode->pSyncW.queue));
460
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
12,523!
461
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
462
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
12,523!
463
        taosQueueGetThreadId(pVnode->pApplyW.queue));
464
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
12,523!
465
  dInfo("vgId:%d, stream-reader-queue:%p is alloced", pVnode->vgId, pVnode->pStreamReaderQ);
12,523!
466
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
12,523!
467
        taosQueueGetThreadId(pVnode->pFetchQ));
468
  return 0;
12,523✔
469
}
470

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

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

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

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

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

497
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
2,410✔
498

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

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

507
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
2,410!
508

509
  int32_t threadNum = 0;
2,410✔
510
  if (tsNumOfCores == 1) {
2,410!
UNCOV
511
    threadNum = 2;
×
512
  } else {
513
    threadNum = tsNumOfCores;
2,410✔
514
  }
515
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
2,410✔
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;
2,410!
522
  dDebug("vnode workers are initialized");
2,410✔
523
  return 0;
2,410✔
524
}
525

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