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

taosdata / TDengine / #4852

14 Nov 2025 08:06AM UTC coverage: 63.812% (+0.06%) from 63.754%
#4852

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

355 of 675 new or added lines in 18 files covered. (52.59%)

3142 existing lines in 128 files now uncovered.

149263 of 233910 relevant lines covered (63.81%)

118719500.98 hits per line

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

81.77
/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) {
8,173,425✔
21
  if (pMsg->info.handle == NULL) return;
8,173,425✔
22
  SRpcMsg rsp = {
16,329,888✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
8,172,700✔
25
      .contLen = pMsg->info.rspLen,
8,172,700✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
8,173,425✔
29
}
30

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

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

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
3,053,302✔
60
  rpcFreeCont(pMsg->pCont);
3,053,302✔
61
  taosFreeQitem(pMsg);
3,050,215✔
62
}
3,052,132✔
63

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

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

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

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

120
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
243,921,653✔
121
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
243,921,653✔
122
  if (code != 0) {
243,923,842✔
123
    if (terrno != 0) code = terrno;
92,340✔
124
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
92,340✔
125
    vmSendRsp(pMsg, code);
92,340✔
126
  }
127

128
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
243,923,842✔
129
  rpcFreeCont(pMsg->pCont);
243,923,842✔
130
  taosFreeQitem(pMsg);
243,923,413✔
131
}
243,924,627✔
132

133
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
555,075,690✔
134
  SVnodeObj *pVnode = pInfo->ahandle;
555,075,690✔
135
  SRpcMsg   *pMsg = NULL;
555,085,111✔
136

137
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,126,017,538✔
138
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
570,863,969✔
139
    const STraceId *trace = &pMsg->info.traceId;
570,851,431✔
140
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
570,909,416✔
141

142
    terrno = 0;
570,910,134✔
143
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
570,886,588✔
144
    if (code != 0) {
570,943,744✔
145
      if (code == -1 && terrno != 0) {
676,968✔
146
        code = terrno;
×
147
      }
148

149
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
676,968✔
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());
676,968✔
153
      }
154

155
      vmSendRsp(pMsg, code);
676,968✔
156
    }
157

158
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
570,943,744✔
159
    rpcFreeCont(pMsg->pCont);
570,943,744✔
160
    taosFreeQitem(pMsg);
570,939,950✔
161
  }
162
}
555,155,266✔
163

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

169
  terrno = 0;
42,806,799✔
170
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
42,809,187✔
171
  if (code != 0) {
42,801,198✔
172
    if (code == -1 && terrno != 0) {
62,134✔
173
      code = terrno;
×
174
    }
175

176
    if (code == 0) {
62,134✔
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());
62,134✔
180
    }
181
  }
182

183
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
42,801,198✔
184
  rpcFreeCont(pMsg->pCont);
42,801,198✔
185
  taosFreeQitem(pMsg);
42,796,000✔
186
}
42,797,676✔
187

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

192
  for (int32_t i = 0; i < numOfMsgs; ++i) {
425,457,077✔
193
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
218,683,526✔
194
    const STraceId *trace = &pMsg->info.traceId;
218,682,192✔
195
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
218,688,574✔
196

197
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
218,688,574✔
198
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
218,682,744✔
199
    rpcFreeCont(pMsg->pCont);
218,683,968✔
200
    taosFreeQitem(pMsg);
218,663,072✔
201
  }
202
}
206,774,251✔
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) {
571,904,638✔
214
  STfs *pTfs = pVnode->pImpl->pTfs;
571,904,638✔
215
  if (pTfs) {
571,918,886✔
216
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
571,918,886✔
217
  } else {
218
    return osDataSpaceSufficient();
×
219
  }
220
}
221

222
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
1,735,094,454✔
223
  *pNode = vmAcquireVnode(pMgt, vgId);
1,735,094,454✔
224
  if (*pNode == NULL) {
1,735,225,972✔
225
    return terrno;
2,073,664✔
226
  }
227
  return 0;
1,732,998,631✔
228
}
229
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
1,735,132,185✔
230
  int32_t         code = 0;
1,735,132,185✔
231
  SMsgHead *      pHead = pMsg->pCont;
1,735,132,185✔
232
  SVnodeObj *     pVnode = NULL;
1,735,060,078✔
233
  const STraceId *trace = &pMsg->info.traceId;
1,735,079,552✔
234

235
  if (pMsg->contLen < sizeof(SMsgHead)) {
1,735,090,928✔
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,735,079,258✔
242
  pHead->vgId = ntohl(pHead->vgId);
1,735,134,510✔
243
  
244
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
1,735,166,545✔
245
  if (code != 0) {
1,735,052,409✔
246
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
2,073,664✔
247
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
248
    return code;
2,073,664✔
249
  }
250

251
  switch (qtype) {
1,732,978,745✔
252
    case QUERY_QUEUE:
243,912,199✔
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);
243,912,199✔
256
      if (code) {
243,917,895✔
UNCOV
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));
243,917,895✔
260
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
243,917,895✔
261
      }
262
      break;
243,918,300✔
263
    case FETCH_QUEUE:
570,857,677✔
264
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
570,857,677✔
265
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
570,857,677✔
266
      break;
570,915,537✔
267
    case WRITE_QUEUE:
571,893,848✔
268
      if (!vmDataSpaceSufficient(pVnode)) {
571,893,848✔
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) {
571,899,654✔
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
64,275✔
284
               TMSG_INFO(pMsg->msgType));
285
        code = TSDB_CODE_VND_STOPPED;
64,275✔
286
        break;
64,275✔
287
      }
288
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
571,823,337✔
289
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
571,823,508✔
290
      break;
571,858,457✔
291
    case SYNC_QUEUE:
168,739,392✔
292
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
168,739,392✔
293
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
168,739,392✔
294
      break;
168,747,303✔
295
    case SYNC_RD_QUEUE:
49,926,827✔
296
      if(tsSyncLogHeartbeat){
49,926,827✔
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));
49,926,827✔
301
      }
302
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
49,926,827✔
303
      break;
49,939,898✔
304
    case APPLY_QUEUE:
84,866,494✔
305
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
84,866,494✔
306
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
84,866,494✔
307
      break;
84,868,370✔
308
    case STREAM_READER_QUEUE:
42,782,308✔
309
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
42,782,308✔
310
              TMSG_INFO(pMsg->msgType));
311
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
42,783,080✔
312
      break;
42,805,073✔
313
    default:
×
314
      code = TSDB_CODE_INVALID_MSG;
×
315
      break;
×
316
  }
317

318
  vmReleaseVnode(pMgmt, pVnode);
1,733,117,213✔
319
  return code;
1,733,126,966✔
320
}
321

322
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
50,202,302✔
323

324
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
99,392,662✔
325

326
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
571,052,756✔
327

328
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
189,134,770✔
329

330
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
571,000,411✔
331

332
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
42,802,789✔
333

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

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

346
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
211,587,834✔
347
  int32_t code;
348
  if (pRpc->contLen < sizeof(SMsgHead)) {
211,587,834✔
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;
211,587,840✔
357
  SRpcMsg *pMsg;
211,559,585✔
358
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
211,587,822✔
359
  if (code) {
211,587,972✔
360
    rpcFreeCont(pRpc->pCont);
×
361
    pRpc->pCont = NULL;
×
362
    return code;
×
363
  }
364

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

368
  pHead->contLen = htonl(pHead->contLen);
211,588,044✔
369
  pHead->vgId = htonl(pHead->vgId);
211,585,428✔
370
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
211,588,520✔
371
  pRpc->pCont = NULL;
211,588,520✔
372

373
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
211,587,923✔
374
  if (code != 0) {
211,588,680✔
375
    dTrace("msg:%p, is freed", pMsg);
1,402,239✔
376
    rpcFreeCont(pMsg->pCont);
1,402,239✔
377
    taosFreeQitem(pMsg);
1,402,239✔
378
  }
379

380
  return code;
211,586,397✔
381
}
382

383
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
17,022,761✔
384
  int32_t    size = -1;
17,022,761✔
385
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
17,022,761✔
386
  if (pVnode != NULL) {
17,023,071✔
387
    switch (qtype) {
8,652,914✔
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,652,914✔
395
        size = taosQueueItemSize(pVnode->pApplyW.queue);
8,652,914✔
396
        break;
8,653,526✔
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);
17,023,683✔
411
  if (size < 0) {
17,021,908✔
412
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
8,368,514✔
413
    size = 0;
8,369,716✔
414
  }
415
  return size;
17,023,110✔
416
}
417

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

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

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

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

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

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

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

497
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
679,020✔
498

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

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

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

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

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