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

taosdata / TDengine / #5041

29 Apr 2026 11:44AM UTC coverage: 73.109% (-0.02%) from 73.13%
#5041

push

travis-ci

web-flow
feat(statewindow): support multi columns (#35136)

1565 of 1828 new or added lines in 18 files covered. (85.61%)

7341 existing lines in 150 files now uncovered.

277332 of 379338 relevant lines covered (73.11%)

133126760.03 hits per line

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

82.07
/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) {
13,007,100✔
21
  if (pMsg->info.handle == NULL) return;
13,007,100✔
22
  SRpcMsg rsp = {
26,020,553✔
23
      .code = code,
24
      .pCont = pMsg->info.rsp,
13,013,023✔
25
      .contLen = pMsg->info.rspLen,
13,012,529✔
26
      .info = pMsg->info,
27
  };
28
  tmsgSendRsp(&rsp);
13,012,686✔
29
}
30

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

36
  dGTrace("msg:%p, get from vnode-multi-mgmt queue", pMsg);
3,364,261✔
37
  switch (pMsg->msgType) {
3,364,261✔
38
    case TDMT_DND_CREATE_VNODE:
3,362,733✔
39
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
3,362,733✔
40
      break;
3,362,394✔
41
#ifdef USE_MOUNT
42
    case TDMT_DND_RETRIEVE_MOUNT_PATH:
1,032✔
43
      code = vmProcessRetrieveMountPathReq(pMgmt, pMsg);
1,032✔
44
      break;
1,032✔
45
    case TDMT_DND_MOUNT_VNODE:
1,180✔
46
      code = vmProcessMountVnodeReq(pMgmt, pMsg);
1,180✔
47
      break;
1,180✔
48
#endif
49
  }
50

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

59
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
3,363,594✔
60
  rpcFreeCont(pMsg->pCont);
3,363,594✔
61
  taosFreeQitem(pMsg);
3,364,680✔
62
}
3,364,908✔
63

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

69
  dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
4,985,878✔
70
  switch (pMsg->msgType) {
4,985,878✔
71
    case TDMT_DND_CREATE_VNODE:
×
72
      code = vmProcessCreateVnodeReq(pMgmt, pMsg);
×
73
      break;
×
74
    case TDMT_DND_DROP_VNODE:
1,784,698✔
75
      code = vmProcessDropVnodeReq(pMgmt, pMsg);
1,784,698✔
76
      break;
1,784,698✔
77
    case TDMT_VND_ALTER_REPLICA:
708,560✔
78
      code = vmProcessAlterVnodeReplicaReq(pMgmt, pMsg);
708,560✔
79
      break;
708,560✔
80
    case TDMT_VND_DISABLE_WRITE:
27,851✔
81
      code = vmProcessDisableVnodeWriteReq(pMgmt, pMsg);
27,851✔
82
      break;
27,851✔
83
    case TDMT_VND_SET_KEEP_VERSION:
3,600✔
84
      code = vmProcessSetKeepVersionReq(pMgmt, pMsg);
3,600✔
85
      break;
3,600✔
86
    case TDMT_VND_ALTER_HASHRANGE:
27,089✔
87
      code = vmProcessAlterHashRangeReq(pMgmt, pMsg);
27,089✔
88
      break;
27,089✔
89
    case TDMT_DND_ALTER_VNODE_TYPE:
2,137,384✔
90
      code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
2,137,384✔
91
      break;
2,137,384✔
92
    case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
×
93
      code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
×
94
      break;
×
95
    case TDMT_VND_ARB_HEARTBEAT:
133,325✔
96
      code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
133,325✔
97
      break;
133,325✔
98
    case TDMT_VND_ALTER_ELECTBASELINE:
31,905✔
99
      code = vmProcessAlterVnodeElectBaselineReq(pMgmt, pMsg);
31,905✔
100
      break;
31,905✔
101
    case TDMT_DND_QUERY_COMPACT_PROGRESS:
131,466✔
102
      code = vmProcessDnodeQueryCompactProgressReq(pMgmt, pMsg);
131,466✔
103
      break;
131,466✔
104
    default:
×
105
      terrno = TSDB_CODE_MSG_NOT_PROCESSED;
×
106
      dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
×
107
  }
108

109
  if (IsReq(pMsg)) {
4,985,878✔
110
    if (code != 0) {
4,985,878✔
111
      if (terrno != 0) code = terrno;
2,035,209✔
112
      dGError("msg:%p, failed to process since %s, type:%s", pMsg, tstrerror(code), TMSG_INFO(pMsg->msgType));
2,035,209✔
113
    }
114
    vmSendRsp(pMsg, code);
4,985,878✔
115
  }
116

117
  dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
4,985,878✔
118
  rpcFreeCont(pMsg->pCont);
4,985,878✔
119
  taosFreeQitem(pMsg);
4,985,878✔
120
}
4,985,878✔
121

122
static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
703,268,987✔
123
  SVnodeObj      *pVnode = pInfo->ahandle;
703,268,987✔
124
  const STraceId *trace = &pMsg->info.traceId;
703,274,025✔
125

126
  dGTrace("vgId:%d, msg:%p, get from vnode-query queue", pVnode->vgId, pMsg);
703,273,051✔
127
  int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg, pInfo);
703,273,051✔
128
  if (code != 0) {
703,209,217✔
129
    if (terrno != 0) code = terrno;
3,845,848✔
130
    dGError("vgId:%d, msg:%p, failed to query since %s", pVnode->vgId, pMsg, tstrerror(code));
3,845,848✔
131
    vmSendRsp(pMsg, code);
3,845,848✔
132
  }
133

134
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
703,208,868✔
135
  rpcFreeCont(pMsg->pCont);
703,208,868✔
136
  taosFreeQitem(pMsg);
703,202,791✔
137
}
703,204,393✔
138

139
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
1,063,743,726✔
140
  SVnodeObj *pVnode = pInfo->ahandle;
1,063,743,726✔
141
  SRpcMsg   *pMsg = NULL;
1,063,773,375✔
142

143
  for (int32_t i = 0; i < numOfMsgs; ++i) {
2,147,483,647✔
144
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
1,103,587,271✔
145
    const STraceId *trace = &pMsg->info.traceId;
1,103,620,420✔
146
    dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
1,103,651,945✔
147

148
    terrno = 0;
1,103,652,597✔
149
    int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
1,103,674,982✔
150
    if (code != 0) {
1,103,723,109✔
151
      if (code == -1 && terrno != 0) {
816,352✔
152
        code = terrno;
×
153
      }
154

155
      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
816,352✔
156
        dGDebug("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
×
157
      } else {
158
        dGError("vgId:%d, msg:%p, failed to fetch since %s [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, terrstr());
816,352✔
159
      }
160

161
      vmSendRsp(pMsg, code);
816,352✔
162
    }
163

164
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vnodeProcessFetchMsg]", pVnode->vgId, pMsg, code);
1,103,723,109✔
165
    rpcFreeCont(pMsg->pCont);
1,103,723,109✔
166
    taosFreeQitem(pMsg);
1,103,727,427✔
167
  }
168
}
1,063,783,918✔
169

170
static void vmProcessStreamReaderQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
56,657,118✔
171
  SVnodeObj *pVnode = pInfo->ahandle;
56,657,118✔
172
  const STraceId *trace = &pMsg->info.traceId;
56,657,118✔
173
  dGTrace("vgId:%d, msg:%p, get from vnode-fetch queue", pVnode->vgId, pMsg);
56,655,180✔
174

175
  terrno = 0;
56,655,304✔
176
  int32_t code = vnodeProcessStreamReaderMsg(pVnode->pImpl, pMsg, pInfo);
56,656,567✔
177
  if (code != 0) {
56,651,344✔
178
    if (code == -1 && terrno != 0) {
134,100✔
179
      code = terrno;
×
180
    }
181

182
    if (code == 0) {
134,100✔
183
      dGDebug("vgId:%d, msg:%p, success to stream reader since %s [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, terrstr());
×
184
    } else {
185
      dGError("vgId:%d, msg:%p, failed to stream reader since %s [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, terrstr());
134,100✔
186
    }
187
  }
188

189
  dGTrace("vgId:%d, msg:%p, is freed, code:0x%x [vmProcessStreamReaderQueue]", pVnode->vgId, pMsg, code);
56,651,538✔
190
  rpcFreeCont(pMsg->pCont);
56,651,538✔
191
  taosFreeQitem(pMsg);
56,652,824✔
192
}
56,652,383✔
193

194
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
551,277,994✔
195
  SVnodeObj *pVnode = pInfo->ahandle;
551,277,994✔
196
  SRpcMsg   *pMsg = NULL;
551,278,468✔
197

198
  for (int32_t i = 0; i < numOfMsgs; ++i) {
1,648,030,173✔
199
    if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
1,096,752,365✔
200
    const STraceId *trace = &pMsg->info.traceId;
1,096,747,719✔
201
    dGTrace("vgId:%d, msg:%p, get from vnode-sync queue", pVnode->vgId, pMsg);
1,096,747,813✔
202

203
    int32_t code = vnodeProcessSyncMsg(pVnode->pImpl, pMsg, NULL);  // no response here
1,096,747,813✔
204
    dGTrace("vgId:%d, msg:%p, is freed, code:0x%x", pVnode->vgId, pMsg, code);
1,096,751,780✔
205
    rpcFreeCont(pMsg->pCont);
1,096,753,586✔
206
    taosFreeQitem(pMsg);
1,096,726,854✔
207
  }
208
}
551,283,380✔
209

210
static void vmSendResponse(SRpcMsg *pMsg) {
×
211
  if (pMsg->info.handle) {
×
212
    SRpcMsg rsp = {.info = pMsg->info, .code = terrno};
×
213
    if (rpcSendResponse(&rsp) != 0) {
×
214
      dError("failed to send response since %s", terrstr());
×
215
    }
216
  }
217
}
×
218

219
static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
782,086,330✔
220
  STfs *pTfs = pVnode->pImpl->pTfs;
782,086,330✔
221
  if (pTfs) {
782,108,729✔
222
    return tfsDiskSpaceSufficient(pTfs, 0, pVnode->diskPrimary);
782,108,729✔
223
  } else {
224
    return osDataSpaceSufficient();
×
225
  }
226
}
227

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

241
  if (pMsg->contLen < sizeof(SMsgHead)) {
2,147,483,647✔
242
    dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
×
243
            pMsg->contLen);
244
    return TSDB_CODE_INVALID_MSG;
×
245
  }
246

247
  pHead->contLen = ntohl(pHead->contLen);
2,147,483,647✔
248
  pHead->vgId = ntohl(pHead->vgId);
2,147,483,647✔
249
  
250
  code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
2,147,483,647✔
251
  if (code != 0) {
2,147,483,647✔
252
    dGDebug("vgId:%d, msg:%p, failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
13,575,674✔
253
            tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
254
    return code;
13,575,277✔
255
  }
256

257
  switch (qtype) {
2,147,483,647✔
258
    case QUERY_QUEUE:
703,174,055✔
259
      // let's put into different query processing queue. The query type is extracted during preprocessing procedure,
260
      // mquery-queue for meta info query, and query-queue for ordinary users' queries.
261
      code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
703,174,055✔
262
      if (code) {
703,141,865✔
263
        dError("vgId:%d, msg:%p, preprocess query msg failed since %s", pVnode->vgId, pMsg, tstrerror(code));
×
264
      } else {
265
        dGTrace("vgId:%d, msg:%p, put into vnode-query queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
703,141,865✔
266
        code = taosWriteQitem(pVnode->pQueryQ, pMsg);
703,141,865✔
267
      }
268
      break;
703,184,637✔
269
    case FETCH_QUEUE:
1,103,530,322✔
270
      dGTrace("vgId:%d, msg:%p, put into vnode-fetch queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,103,530,322✔
271
      code = taosWriteQitem(pVnode->pFetchQ, pMsg);
1,103,530,322✔
272
      break;
1,103,742,070✔
273
    case WRITE_QUEUE:
782,090,391✔
274
      if (!vmDataSpaceSufficient(pVnode)) {
782,090,391✔
275
        code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
×
276
        dError("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
×
277
               tstrerror(code), TMSG_INFO(pMsg->msgType));
278
        break;
×
279
      }
280
#if 0
281
      if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
282
        code = TSDB_CODE_VND_NO_WRITE_AUTH;
283
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
284
               tstrerror(code), TMSG_INFO(pMsg->msgType));
285
        break;
286
      }
287
#endif
288
      if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
782,091,118✔
289
        dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
74,152✔
290
               TMSG_INFO(pMsg->msgType));
291
        code = TSDB_CODE_VND_STOPPED;
74,152✔
292
        break;
74,152✔
293
      }
294
      dGDebug("vgId:%d, msg:%p, put into vnode-write queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
781,998,470✔
295
      code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
781,999,420✔
296
      break;
782,043,110✔
297
    case SYNC_QUEUE:
1,046,636,818✔
298
      dGDebug("vgId:%d, msg:%p, put into vnode-sync queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
1,046,636,818✔
299
      code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
1,046,636,818✔
300
      break;
1,046,722,983✔
301
    case SYNC_RD_QUEUE:
50,025,232✔
302
      if(tsSyncLogHeartbeat){
50,025,232✔
303
        dGInfo("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
×
304
      }
305
      else{
306
        dGDebug("vgId:%d, msg:%p, put into vnode-sync-rd queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
50,025,232✔
307
      }
308
      code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
50,025,232✔
309
      break;
50,034,158✔
310
    case APPLY_QUEUE:
600,669,536✔
311
      dGDebug("vgId:%d, msg:%p, put into vnode-apply queue, type:%s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
600,669,536✔
312
      code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
600,669,536✔
313
      break;
600,670,694✔
314
    case STREAM_READER_QUEUE:
56,650,337✔
315
      dGDebug("vgId:%d, msg:%p, put into vnode-stream-reader queue, type:%s", pVnode->vgId, pMsg,
56,650,337✔
316
              TMSG_INFO(pMsg->msgType));
317
      code = taosWriteQitem(pVnode->pStreamReaderQ, pMsg);
56,651,131✔
318
      break;
56,655,324✔
UNCOV
319
    default:
×
UNCOV
320
      code = TSDB_CODE_INVALID_MSG;
×
UNCOV
321
      break;
×
322
  }
323

324
  vmReleaseVnode(pMgmt, pVnode);
2,147,483,647✔
325
  return code;
2,147,483,647✔
326
}
327

328
int32_t vmPutMsgToSyncRdQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_RD_QUEUE); }
50,261,735✔
329

330
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
860,829,525✔
331

332
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
781,044,841✔
333

334
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
659,735,837✔
335

336
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
1,103,707,642✔
337

338
int32_t vmPutMsgToStreamReaderQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_READER_QUEUE); }
56,671,370✔
339

340
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
3,364,156✔
341
  const STraceId *trace = &pMsg->info.traceId;
3,364,156✔
342
  dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
3,364,156✔
343
  return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
3,364,156✔
344
}
345

346
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
4,984,289✔
347
  const STraceId *trace = &pMsg->info.traceId;
4,984,289✔
348
  dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
4,985,878✔
349
  return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
4,985,878✔
350
}
351

352
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
844,223,942✔
353
  int32_t code;
354
  if (pRpc->contLen < sizeof(SMsgHead)) {
844,223,942✔
355
    dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
×
356
           pRpc->contLen);
357
    rpcFreeCont(pRpc->pCont);
×
358
    pRpc->pCont = NULL;
×
359
    return TSDB_CODE_INVALID_MSG;
×
360
  }
361

362
  EQItype  itype = APPLY_QUEUE == qtype ? APPLY_QITEM : RPC_QITEM;
844,232,800✔
363
  SRpcMsg *pMsg;
844,224,383✔
364
  code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
844,229,674✔
365
  if (code) {
844,212,151✔
366
    rpcFreeCont(pRpc->pCont);
×
367
    pRpc->pCont = NULL;
×
368
    return code;
×
369
  }
370

371
  SMsgHead *pHead = pRpc->pCont;
844,212,151✔
372
  dTrace("vgId:%d, msg:%p, is created, type:%s len:%d", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType), pRpc->contLen);
844,214,207✔
373

374
  pHead->contLen = htonl(pHead->contLen);
844,214,207✔
375
  pHead->vgId = htonl(pHead->vgId);
844,217,121✔
376
  memcpy(pMsg, pRpc, sizeof(SRpcMsg));
844,218,276✔
377
  pRpc->pCont = NULL;
844,218,276✔
378

379
  code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
844,230,651✔
380
  if (code != 0) {
844,224,273✔
381
    dTrace("msg:%p, is freed", pMsg);
1,636,111✔
382
    rpcFreeCont(pMsg->pCont);
1,636,111✔
383
    taosFreeQitem(pMsg);
1,636,111✔
384
  }
385

386
  return code;
844,229,658✔
387
}
388

389
int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
19,895,490✔
390
  int32_t    size = -1;
19,895,490✔
391
  SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
19,895,490✔
392
  if (pVnode != NULL) {
19,897,375✔
393
    switch (qtype) {
10,835,541✔
394
      case WRITE_QUEUE:
×
395
        size = taosQueueItemSize(pVnode->pWriteW.queue);
×
396
        break;
×
397
      case SYNC_QUEUE:
×
398
        size = taosQueueItemSize(pVnode->pSyncW.queue);
×
399
        break;
×
400
      case APPLY_QUEUE:
10,835,541✔
401
        size = taosQueueItemSize(pVnode->pApplyW.queue);
10,835,541✔
402
        break;
10,838,465✔
403
      case QUERY_QUEUE:
×
404
        size = taosQueueItemSize(pVnode->pQueryQ);
×
405
        break;
×
406
      case FETCH_QUEUE:
×
407
        size = taosQueueItemSize(pVnode->pFetchQ);
×
408
        break;
×
409
      case STREAM_READER_QUEUE:
×
410
        size = taosQueueItemSize(pVnode->pStreamReaderQ);
×
411
        break;
×
412
      default:
×
413
        break;
×
414
    }
415
  }
416
  if (pVnode) vmReleaseVnode(pMgmt, pVnode);
19,900,299✔
417
  if (size < 0) {
19,894,728✔
418
    dTrace("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
9,056,266✔
419
    size = 0;
9,056,554✔
420
  }
421
  return size;
19,895,016✔
422
}
423

424
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
4,533,456✔
425
  int32_t         code = 0;
4,533,456✔
426
  SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
4,533,456✔
427
  SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
4,533,392✔
428
  SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
4,533,456✔
429
  SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl};
4,533,026✔
430
  code = tMultiWorkerInit(&pVnode->pWriteW, &wcfg);
4,533,394✔
431
  if (code) {
4,534,214✔
432
    return code;
×
433
  }
434
  code = tMultiWorkerInit(&pVnode->pSyncW, &scfg);
4,534,214✔
435
  if (code) {
4,534,024✔
436
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
437
    return code;
×
438
  }
439
  code = tMultiWorkerInit(&pVnode->pSyncRdW, &sccfg);
4,534,024✔
440
  if (code) {
4,534,214✔
441
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
442
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
443
    return code;
×
444
  }
445
  code = tMultiWorkerInit(&pVnode->pApplyW, &acfg);
4,534,214✔
446
  if (code) {
4,534,214✔
447
    tMultiWorkerCleanup(&pVnode->pWriteW);
×
448
    tMultiWorkerCleanup(&pVnode->pSyncW);
×
449
    tMultiWorkerCleanup(&pVnode->pSyncRdW);
×
450
    return code;
×
451
  }
452

453
  pVnode->pQueryQ = tQueryAutoQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
4,534,214✔
454
  pVnode->pStreamReaderQ = tQueryAutoQWorkerAllocQueue(&pMgmt->streamReaderPool, pVnode, (FItem)vmProcessStreamReaderQueue);
4,534,214✔
455
  pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
4,534,214✔
456

457
  if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
4,534,214✔
458
      pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL || !pVnode->pStreamReaderQ) {
4,534,214✔
459
    return TSDB_CODE_OUT_OF_MEMORY;
×
460
  }
461

462
  dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
4,534,214✔
463
        taosQueueGetThreadId(pVnode->pWriteW.queue));
464
  dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue,
4,534,214✔
465
        taosQueueGetThreadId(pVnode->pSyncW.queue));
466
  dInfo("vgId:%d, sync-rd-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncRdW.queue,
4,534,214✔
467
        taosQueueGetThreadId(pVnode->pSyncRdW.queue));
468
  dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue,
4,534,214✔
469
        taosQueueGetThreadId(pVnode->pApplyW.queue));
470
  dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
4,534,214✔
471
  dInfo("vgId:%d, stream-reader-queue:%p is alloced", pVnode->vgId, pVnode->pStreamReaderQ);
4,534,214✔
472
  dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ,
4,534,214✔
473
        taosQueueGetThreadId(pVnode->pFetchQ));
474
  return 0;
4,534,214✔
475
}
476

477
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
4,534,089✔
478
  tQueryAutoQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
4,534,089✔
479
  tQueryAutoQWorkerFreeQueue(&pMgmt->streamReaderPool, pVnode->pStreamReaderQ);
4,534,214✔
480
  tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
4,534,214✔
481

482
  pVnode->pQueryQ = NULL;
4,534,214✔
483
  pVnode->pFetchQ = NULL;
4,534,214✔
484
  pVnode->pStreamReaderQ = NULL;
4,534,214✔
485
  dDebug("vgId:%d, queue is freed", pVnode->vgId);
4,534,214✔
486
}
4,534,214✔
487

488
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
660,730✔
489
  int32_t code = 0;
660,730✔
490

491
  SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
660,730✔
492
  pQPool->name = "vnode-query";
660,730✔
493
  pQPool->min = tsNumOfVnodeQueryThreads;
660,730✔
494
  pQPool->max = tsNumOfVnodeQueryThreads;
660,730✔
495
  if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
660,730✔
496

497
  SQueryAutoQWorkerPool *pSPool = &pMgmt->streamReaderPool;
660,730✔
498
  pSPool->name = "vnode-st-reader";
660,730✔
499
  pSPool->min = tsNumOfVnodeStreamReaderThreads;
660,730✔
500
  pSPool->max = tsNumOfVnodeStreamReaderThreads;
660,730✔
501
  if ((code = tQueryAutoQWorkerInit(pSPool)) != 0) return code;
660,730✔
502

503
  tsNumOfQueryThreads += tsNumOfVnodeQueryThreads;
660,730✔
504

505
  SWWorkerPool *pFPool = &pMgmt->fetchPool;
660,730✔
506
  pFPool->name = "vnode-fetch";
660,730✔
507
  pFPool->max = tsNumOfVnodeFetchThreads;
660,730✔
508
  if ((code = tWWorkerInit(pFPool)) != 0) return code;
660,730✔
509

510
  SSingleWorkerCfg mgmtCfg = {
660,730✔
511
      .min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
512

513
  if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
660,730✔
514

515
  int32_t threadNum = 0;
660,730✔
516
  if (tsNumOfCores == 1) {
660,730✔
517
    threadNum = 2;
×
518
  } else {
519
    threadNum = tsNumOfCores;
660,730✔
520
  }
521
  SSingleWorkerCfg multiMgmtCfg = {.min = threadNum,
660,730✔
522
                                   .max = threadNum,
523
                                   .name = "vnode-multi-mgmt",
524
                                   .fp = (FItem)vmProcessMultiMgmtQueue,
525
                                   .param = pMgmt};
526

527
  if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
660,730✔
528
  dDebug("vnode workers are initialized");
660,730✔
529
  return 0;
660,730✔
530
}
531

532
void vmStopWorker(SVnodeMgmt *pMgmt) {
660,730✔
533
  tQueryAutoQWorkerCleanup(&pMgmt->queryPool);
660,730✔
534
  tWWorkerCleanup(&pMgmt->fetchPool);
660,730✔
535
  tQueryAutoQWorkerCleanup(&pMgmt->streamReaderPool);
660,730✔
536
  dDebug("vnode workers are closed");
660,730✔
537
}
660,730✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc