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

taosdata / TDengine / #4857

17 Nov 2025 09:53AM UTC coverage: 64.135% (-0.2%) from 64.286%
#4857

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

218 of 311 new or added lines in 32 files covered. (70.1%)

5044 existing lines in 121 files now uncovered.

151302 of 235910 relevant lines covered (64.14%)

116627960.99 hits per line

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

82.19
/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,213,764✔
21
  if (pMsg->info.handle == NULL) return;
8,213,764✔
22
  SRpcMsg rsp = {
16,409,242✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
8,213,764✔
25
      .contLen = pMsg->info.rspLen,
8,213,084✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
8,212,875✔
29
}
30

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

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

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
3,070,184✔
60
  rpcFreeCont(pMsg->pCont);
3,070,184✔
61
  taosFreeQitem(pMsg);
3,070,182✔
62
}
3,069,754✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
4,369,917✔
70
  switch (pMsg->msgType) {
4,369,917✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
1,624,777✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
1,624,777✔
76
      break;
1,624,777✔
77
    case TDMT_VND_ALTER_REPLICA:
633,700✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
633,700✔
79
      break;
633,700✔
80
    case TDMT_VND_DISABLE_WRITE:
21,500✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
21,500✔
82
      break;
21,500✔
83
    case TDMT_VND_SET_KEEP_VERSION:
3,628✔
84
      code = vmProcessSetKeepVersionReq(pMgmt, pMsg);
3,628✔
85
      break;
3,628✔
86
    case TDMT_VND_ALTER_HASHRANGE:
20,770✔
87
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
20,770✔
88
      break;
20,770✔
89
    case TDMT_DND_ALTER_VNODE_TYPE:
1,922,201✔
90
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
1,922,201✔
91
      break;
1,922,201✔
UNCOV
92
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
UNCOV
93
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
UNCOV
94
      break;
×
95
    case TDMT_VND_ARB_HEARTBEAT:
106,854✔
96
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
106,854✔
97
      break;
106,854✔
98
    case TDMT_VND_ALTER_ELECTBASELINE:
36,487✔
99
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
36,487✔
100
      break;
36,487✔
UNCOV
101
    default:
×
UNCOV
102
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
UNCOV
103
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
104
  }
105

106
  if (IsReq(pMsg)) {
4,369,917✔
107
    if (code != 0) {
4,369,917✔
108
      if (terrno != 0) code = terrno;
1,830,028✔
109
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
1,830,028✔
110
    }
111
    vmSendRsp(pMsg, code);
4,369,917✔
112
  }
113

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

119
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
224,583,699✔
120
  SVnodeObj      *pVnode = pInfo->ahandle;
224,583,699✔
121
  const STraceId *trace = &pMsg->info.traceId;
224,586,313✔
122

123
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
224,586,879✔
124
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
224,587,086✔
125
  if (code != 0) {
224,587,161✔
126
    if (terrno != 0) code = terrno;
93,654✔
127
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
93,654✔
128
    vmSendRsp(pMsg, code);
93,654✔
129
  }
130

131
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
224,587,161✔
132
  rpcFreeCont(pMsg->pCont);
224,587,161✔
133
  taosFreeQitem(pMsg);
224,590,014✔
134
}
224,587,266✔
135

136
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
512,981,061✔
137
  SVnodeObj *pVnode = pInfo->ahandle;
512,981,061✔
138
  SRpcMsg   *pMsg = NULL;
512,989,525✔
139

140
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,040,912,371✔
141
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
527,850,069✔
142
    const STraceId *trace = &pMsg->info.traceId;
527,833,732✔
143
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
527,853,321✔
144

145
    terrno = 0;
527,853,488✔
146
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
527,856,853✔
147
    if (code != 0) {
527,923,563✔
148
      if (code == -1 && terrno != 0) {
680,009✔
UNCOV
149
        code = terrno;
×
150
      }
151

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

158
      vmSendRsp(pMsg, code);
680,009✔
159
    }
160

161
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
527,923,563✔
162
    rpcFreeCont(pMsg->pCont);
527,923,563✔
163
    taosFreeQitem(pMsg);
527,917,897✔
164
  }
165
}
513,062,696✔
166

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

172
  terrno = 0;
41,530,442✔
173
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg);
41,531,216✔
174
  if (code != 0) {
41,516,878✔
175
    if (code == -1 && terrno != 0) {
63,548✔
UNCOV
176
      code = terrno;
×
177
    }
178

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

186
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
41,516,878✔
187
  rpcFreeCont(pMsg->pCont);
41,516,878✔
188
  taosFreeQitem(pMsg);
41,521,059✔
189
}
41,516,521✔
190

191
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
218,132,363✔
192
  SVnodeObj *pVnode = pInfo->ahandle;
218,132,363✔
193
  SRpcMsg   *pMsg = NULL;
218,133,818✔
194

195
  for (int32_t i = 0; i < numOfMsgs; ++i) {
448,535,850✔
196
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
230,432,654✔
197
    const STraceId *trace = &pMsg->info.traceId;
230,424,546✔
198
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
230,433,205✔
199

200
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
230,433,205✔
201
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
230,426,405✔
202
    rpcFreeCont(pMsg->pCont);
230,427,627✔
203
    taosFreeQitem(pMsg);
230,402,685✔
204
  }
205
}
218,108,269✔
206

UNCOV
207
static void vmSendResponse(SRpcMsg *pMsg) {
×
UNCOV
208
  if (pMsg->info.handle) {
×
UNCOV
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) {
572,122,023✔
217
  STfs *pTfs = pVnode->pImpl->pTfs;
572,122,023✔
218
  if (pTfs) {
572,153,292✔
219
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
572,153,292✔
220
  } else {
UNCOV
221
    return osDataSpaceSufficient();
×
222
  }
223
}
224

225
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
1,691,772,599✔
226
  *pNode = vmAcquireVnode(pMgt, vgId);
1,691,772,599✔
227
  if (*pNode == NULL) {
1,691,867,548✔
228
    return terrno;
2,142,710✔
229
  }
230
  return 0;
1,689,740,181✔
231
}
232
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
1,691,795,094✔
233
  int32_t         code = 0;
1,691,795,094✔
234
  SMsgHead *      pHead = pMsg->pCont;
1,691,795,094✔
235
  SVnodeObj *     pVnode = NULL;
1,691,734,932✔
236
  const STraceId *trace = &pMsg->info.traceId;
1,691,744,373✔
237

238
  if (pMsg->contLen < sizeof(SMsgHead)) {
1,691,779,941✔
UNCOV
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);
UNCOV
241
    return TSDB_CODE_INVALID_MSG;
×
242
  }
243

244
  pHead->contLen = ntohl(pHead->contLen);
1,691,734,177✔
245
  pHead->vgId = ntohl(pHead->vgId);
1,691,810,687✔
246
  
247
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
1,691,810,138✔
248
  if (code != 0) {
1,691,709,571✔
249
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
2,142,710✔
250
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
251
    return code;
2,142,710✔
252
  }
253

254
  switch (qtype) {
1,689,566,861✔
255
    case QUERY_QUEUE:
224,582,652✔
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);
224,582,652✔
259
      if (code) {
224,583,028✔
260
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
1,389✔
261
      } else {
262
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
224,581,639✔
263
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
224,581,639✔
264
      }
265
      break;
224,586,462✔
266
    case FETCH_QUEUE:
527,811,387✔
267
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
527,811,387✔
268
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
527,811,387✔
269
      break;
527,905,985✔
270
    case WRITE_QUEUE:
572,129,062✔
271
      if (!vmDataSpaceSufficient(pVnode)) {
572,129,062✔
UNCOV
272
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
UNCOV
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) {
572,131,081✔
286
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
71,176✔
287
               TMSG_INFO(pMsg->msgType));
288
        code = TSDB_CODE_VND_STOPPED;
71,176✔
289
        break;
71,176✔
290
      }
291
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
572,055,873✔
292
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
572,058,282✔
293
      break;
572,079,115✔
294
    case SYNC_QUEUE:
179,184,816✔
295
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
179,184,816✔
296
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
179,184,816✔
297
      break;
179,189,789✔
298
    case SYNC_RD_QUEUE:
51,236,316✔
299
      if(tsSyncLogHeartbeat){
51,236,316✔
UNCOV
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));
51,236,316✔
304
      }
305
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
51,236,316✔
306
      break;
51,246,988✔
307
    case APPLY_QUEUE:
93,112,994✔
308
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
93,112,994✔
309
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
93,113,064✔
310
      break;
93,114,920✔
311
    case STREAM_READER_QUEUE:
41,509,634✔
312
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
41,509,634✔
313
              TMSG_INFO(pMsg->msgType));
314
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
41,511,186✔
315
      break;
41,527,835✔
UNCOV
316
    default:
×
UNCOV
317
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
318
      break;
×
319
  }
320

321
  vmReleaseVnode(pMgmt, pVnode);
1,689,722,270✔
322
  return code;
1,689,698,496✔
323
}
324

325
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
51,506,153✔
326

327
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
107,610,477✔
328

329
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
571,180,477✔
330

331
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
174,995,102✔
332

333
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
527,976,031✔
334

335
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
41,524,827✔
336

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

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

349
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
217,046,735✔
350
  int32_t code;
351
  if (pRpc->contLen < sizeof(SMsgHead)) {
217,046,735✔
UNCOV
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);
UNCOV
354
    rpcFreeCont(pRpc->pCont);
×
355
    pRpc->pCont = NULL;
×
UNCOV
356
    return TSDB_CODE_INVALID_MSG;
×
357
  }
358

359
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
217,047,001✔
360
  SRpcMsg *pMsg;
217,019,170✔
361
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
217,047,001✔
362
  if (code) {
217,046,024✔
UNCOV
363
    rpcFreeCont(pRpc->pCont);
×
UNCOV
364
    pRpc->pCont = NULL;
×
UNCOV
365
    return code;
×
366
  }
367

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

371
  pHead->contLen = htonl(pHead->contLen);
217,047,178✔
372
  pHead->vgId = htonl(pHead->vgId);
217,046,793✔
373
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
217,046,878✔
374
  pRpc->pCont = NULL;
217,046,878✔
375

376
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
217,047,304✔
377
  if (code != 0) {
217,048,323✔
378
    dTrace("msg:%p, is freed", pMsg);
1,450,624✔
379
    rpcFreeCont(pMsg->pCont);
1,450,624✔
380
    taosFreeQitem(pMsg);
1,450,624✔
381
  }
382

383
  return code;
217,048,210✔
384
}
385

386
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
21,514,736✔
387
  int32_t    size = -1;
21,514,736✔
388
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
21,514,736✔
389
  if (pVnode != NULL) {
21,514,698✔
390
    switch (qtype) {
13,108,752✔
UNCOV
391
      case WRITE_QUEUE:
×
UNCOV
392
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
UNCOV
393
        break;
×
394
      case SYNC_QUEUE:
×
395
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
396
        break;
×
397
      case APPLY_QUEUE:
13,108,752✔
398
        size = taosQueueItemSize(pVnode->pApplyW.queue);
13,108,752✔
399
        break;
13,109,427✔
UNCOV
400
      case QUERY_QUEUE:
×
UNCOV
401
        size = taosQueueItemSize(pVnode->pQueryQ);
×
UNCOV
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);
21,515,373✔
414
  if (size < 0) {
21,513,377✔
415
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
8,402,976✔
416
    size = 0;
8,403,237✔
417
  }
418
  return size;
21,513,638✔
419
}
420

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

450
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
4,210,677✔
451
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
4,210,677✔
452
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
4,210,677✔
453

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

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

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

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

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

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

500
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
685,974✔
501

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

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

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

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

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