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

taosdata / TDengine / #4829

30 Oct 2025 09:25AM UTC coverage: 49.734% (-11.3%) from 61.071%
#4829

push

travis-ci

web-flow
Merge pull request #33435 from taosdata/3.0

merge 3.0

123072 of 323930 branches covered (37.99%)

Branch coverage included in aggregate %.

7 of 25 new or added lines in 3 files covered. (28.0%)

35232 existing lines in 327 files now uncovered.

172062 of 269495 relevant lines covered (63.85%)

70709785.06 hits per line

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

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

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

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

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
578,398!
60
  rpcFreeCont(pMsg->pCont);
578,398✔
61
  taosFreeQitem(pMsg);
577,605✔
62
}
577,844✔
63

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

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

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

116
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
76,159,472✔
117
  SVnodeObj      *pVnode = pInfo->ahandle;
76,159,472✔
118
  const STraceId *trace = &pMsg->info.traceId;
76,158,884✔
119

120
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
76,159,572!
121
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
76,159,572✔
122
  if (code != 0) {
76,154,438✔
123
    if (terrno != 0) code = terrno;
26,532!
124
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
26,532!
125
    vmSendRsp(pMsg, code);
26,532✔
126
  }
127

128
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
76,154,438!
129
  rpcFreeCont(pMsg->pCont);
76,154,438✔
130
  taosFreeQitem(pMsg);
76,155,925✔
131
}
76,156,737✔
132

133
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
153,621,049✔
134
  SVnodeObj *pVnode = pInfo->ahandle;
153,621,049✔
135
  SRpcMsg   *pMsg = NULL;
153,625,706✔
136

137
  for (int32_t i = 0; i < numOfMsgs; ++i) {
312,584,287✔
138
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
158,940,275!
139
    const STraceId *trace = &pMsg->info.traceId;
158,935,909✔
140
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
158,939,474!
141

142
    terrno = 0;
158,939,916✔
143
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
158,947,706✔
144
    if (code != 0) {
158,968,054✔
145
      if (code == -1 && terrno != 0) {
302,837!
146
        code = terrno;
×
147
      }
148

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

155
      vmSendRsp(pMsg, code);
302,837✔
156
    }
157

158
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
158,968,054!
159
    rpcFreeCont(pMsg->pCont);
158,968,054✔
160
    taosFreeQitem(pMsg);
158,962,207✔
161
  }
162
}
153,638,644✔
163

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

169
  terrno = 0;
5,141,777✔
170
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
5,142,367✔
171
  if (code != 0) {
5,139,363✔
172
    if (code == -1 && terrno != 0) {
25,083!
173
      code = terrno;
×
174
    }
175

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

183
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
5,139,363!
184
  rpcFreeCont(pMsg->pCont);
5,139,363✔
185
  taosFreeQitem(pMsg);
5,139,983✔
186
}
5,140,858✔
187

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

192
  for (int32_t i = 0; i < numOfMsgs; ++i) {
72,932,131✔
193
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
37,020,946!
194
    const STraceId *trace = &pMsg->info.traceId;
37,019,166✔
195
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
37,019,736!
196

197
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
37,019,736✔
198
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
37,017,682!
199
    rpcFreeCont(pMsg->pCont);
37,017,682✔
200
    taosFreeQitem(pMsg);
37,012,631✔
201
  }
202
}
35,912,326✔
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) {
150,465,268✔
214
  STfs *pTfs = pVnode->pImpl->pTfs;
150,465,268✔
215
  if (pTfs) {
150,469,108!
216
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
150,469,108✔
217
  } else {
218
    return osDataSpaceSufficient();
×
219
  }
220
}
221

222
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
437,940,238✔
223
  *pNode = vmAcquireVnode(pMgt, vgId);
437,940,238✔
224
  if (*pNode == NULL) {
438,022,223✔
225
    return terrno;
318,338✔
226
  }
227
  return 0;
437,706,929✔
228
}
229
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
437,967,285✔
230
  int32_t         code = 0;
437,967,285✔
231
  SMsgHead *      pHead = pMsg->pCont;
437,967,285✔
232
  SVnodeObj *     pVnode = NULL;
437,900,625✔
233
  const STraceId *trace = &pMsg->info.traceId;
437,905,315✔
234

235
  if (pMsg->contLen < sizeof(SMsgHead)) {
437,917,784!
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);
437,960,600✔
242
  pHead->vgId = ntohl(pHead->vgId);
437,968,691✔
243
  
244
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
437,976,372✔
245
  if (code != 0) {
437,974,734✔
246
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
318,338!
247
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
248
    return code;
318,338✔
249
  }
250

251
  switch (qtype) {
437,656,396!
252
    case QUERY_QUEUE:
76,149,523✔
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);
76,149,523✔
256
      if (code) {
76,149,973!
257
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
258
      } else {
259
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
76,149,973!
260
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
76,149,973✔
261
      }
262
      break;
76,152,466✔
263
    case FETCH_QUEUE:
158,941,612✔
264
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
158,941,612!
265
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
158,941,612✔
266
      break;
158,965,269✔
267
    case WRITE_QUEUE:
150,462,105✔
268
      if (!vmDataSpaceSufficient(pVnode)) {
150,462,105!
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) {
150,466,170✔
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
10,988!
284
               TMSG_INFO(pMsg->msgType));
285
        code = TSDB_CODE_VND_STOPPED;
10,988✔
286
        break;
10,988✔
287
      }
288
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
150,454,675!
289
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
150,454,869✔
290
      break;
150,461,136✔
291
    case SYNC_QUEUE:
26,857,255✔
292
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
26,857,255!
293
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
26,857,255✔
294
      break;
26,858,967✔
295
    case SYNC_RD_QUEUE:
10,162,822✔
296
      if(tsSyncLogHeartbeat){
10,162,822!
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));
10,162,822!
301
      }
302
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
10,162,822✔
303
      break;
10,164,199✔
304
    case APPLY_QUEUE:
9,944,617✔
305
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
9,944,617!
306
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
9,944,617✔
307
      break;
9,945,019✔
308
    case STREAM_READER_QUEUE:
5,138,462✔
309
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
5,138,462!
310
              TMSG_INFO(pMsg->msgType));
311
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
5,138,462✔
312
      break;
5,140,881✔
313
    default:
×
314
      code = TSDB_CODE_INVALID_MSG;
×
315
      break;
×
316
  }
317

318
  vmReleaseVnode(pMgmt, pVnode);
437,698,925✔
319
  return code;
437,695,729✔
320
}
321

322
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
10,201,388✔
323

324
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
12,993,170✔
325

326
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
150,269,978✔
327

328
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
53,290,280✔
329

330
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
158,973,696✔
331

332
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
5,139,662✔
333

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

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

346
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
47,127,919✔
347
  int32_t code;
348
  if (pRpc->contLen < sizeof(SMsgHead)) {
47,127,919!
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;
47,127,919✔
357
  SRpcMsg *pMsg;
47,127,757✔
358
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
47,128,090✔
359
  if (code) {
47,127,401!
360
    rpcFreeCont(pRpc->pCont);
×
361
    pRpc->pCont = NULL;
×
362
    return code;
×
363
  }
364

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

368
  pHead->contLen = htonl(pHead->contLen);
47,127,594✔
369
  pHead->vgId = htonl(pHead->vgId);
47,127,594✔
370
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
47,127,078!
371
  pRpc->pCont = NULL;
47,127,078✔
372

373
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
47,127,690✔
374
  if (code != 0) {
47,127,617✔
375
    dTrace("msg:%p, is freed", pMsg);
230,838!
376
    rpcFreeCont(pMsg->pCont);
230,838✔
377
    taosFreeQitem(pMsg);
230,838✔
378
  }
379

380
  return code;
47,127,696✔
381
}
382

383
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
2,627,911✔
384
  int32_t    size = -1;
2,627,911✔
385
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
2,627,911✔
386
  if (pVnode != NULL) {
2,628,140✔
387
    switch (qtype) {
1,245,348!
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:
1,245,348✔
395
        size = taosQueueItemSize(pVnode->pApplyW.queue);
1,245,348✔
396
        break;
1,245,440✔
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);
2,628,232✔
411
  if (size < 0) {
2,627,367✔
412
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
1,382,192✔
413
    size = 0;
1,382,192✔
414
  }
415
  return size;
2,627,367✔
416
}
417

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

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

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

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

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

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

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

497
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
141,282✔
498

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

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

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

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

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